Js.Null
Provide utilities around 'a null
Provides functionality for dealing with the 'a Js.null
type
val return : 'a -> 'a t
Constructs a value of 'a Js.null
containing a value of 'a
val test : 'a t -> bool
Returns true
if the given value is empty
(null
), false
otherwise
val empty : 'a t
The empty value, null
val getUnsafe : 'a t -> 'a
val getExn : 'a t -> 'a
val bind : 'a t -> ('a -> 'b) Js.Fn.arity1 -> 'b t
Maps the contained value using the given function
If 'a Js.null
contains a value, that value is unwrapped, mapped to a 'b
using the given function a' -> 'b
, then wrapped back up and returned as 'b Js.null
let maybeGreetWorld (maybeGreeting: string Js.null) =
Js.Null.bind maybeGreeting (fun greeting -> greeting ^ " world!")
val iter : 'a t -> ('a -> unit) Js.Fn.arity1 -> unit
Iterates over the contained value with the given function
If 'a Js.null
contains a value, that value is unwrapped and applied to the given function.
let maybeSay (maybeMessage: string Js.null) =
Js.Null.iter maybeMessage (fun message -> Js.log message)
val fromOption : 'a option -> 'a t
Maps 'a option
to 'a Js.null
Some a | -> | return a |
None | -> | empty |
val from_opt : 'a option -> 'a t
val toOption : 'a t -> 'a option
Maps 'a Js.null
to 'a option
return a | -> | Some a |
empty | -> | None |
val to_opt : 'a t -> 'a option