Module Js.Null
Utility functions on null
Provides functionality for dealing with the 'a Js.nullJs.null('a) type
ocaml
type +'a t = 'a Js.nullreasonml
type t(+'a) = Js.null('a);Local alias for 'a Js.nullJs.null('a)
ocaml
val return : 'a -> 'a treasonml
let return: 'a => t('a);Constructs a value of 'a Js.nullJs.null('a) containing a value of 'a
ocaml
val empty : 'a treasonml
let empty: t('a);The empty value, null
ocaml
val getUnsafe : 'a t -> 'areasonml
let getUnsafe: t('a) => 'a;ocaml
val getExn : 'a t -> 'areasonml
let getExn: t('a) => 'a;ocaml
val bind : f:('a -> 'b t) Js.Fn.arity1 -> 'a t -> 'b treasonml
let bind: f:Js.Fn.arity1(('a => t('b))) => t('a) => t('b);ocaml
val map : f:('a -> 'b) Js.Fn.arity1 -> 'a t -> 'b treasonml
let map: f:Js.Fn.arity1(('a => 'b)) => t('a) => t('b);Maps the contained value using the given function
If 'a Js.nullJs.null('a) contains a value, that value is unwrapped, mapped to a 'b using the given function a' -> 'ba' => 'b, then wrapped back up and returned as 'b Js.nullJs.null('b)
ocaml
let maybeGreetWorld (maybeGreeting: string Js.null) =
Js.Null.bind maybeGreeting ~f:(fun greeting -> greeting ^ " world!")reasonml
let maybeGreetWorld = (maybeGreeting: Js.null(string)) =>
Js.Null.bind(maybeGreeting, ~f=greeting => greeting ++ " world!");ocaml
val iter : f:('a -> unit) Js.Fn.arity1 -> 'a t -> unitreasonml
let iter: f:Js.Fn.arity1(('a => unit)) => t('a) => unit;Iterates over the contained value with the given function
If 'a Js.nullJs.null('a) contains a value, that value is unwrapped and applied to the given function.
ocaml
let maybeSay (maybeMessage: string Js.null) =
Js.Null.iter maybeMessage ~f:(fun message -> Js.log message)reasonml
let maybeSay = (maybeMessage: Js.null(string)) =>
Js.Null.iter(maybeMessage, ~f=message => Js.log(message));ocaml
val fromOption : 'a option -> 'a treasonml
let fromOption: option('a) => t('a);Maps 'a optionoption('a) to 'a Js.nullJs.null('a)
| Some a | return a |
|---|---|
| None | empty |
ocaml
val toOption : 'a t -> 'a optionreasonml
let toOption: t('a) => option('a);Maps 'a Js.nullJs.null('a) to 'a optionoption('a)
| return a | Some a |
|---|---|
| empty | None |