Js.Nullable
Utility functions on nullable
Contains functionality for dealing with values that can be both null
and undefined
type +'a t = 'a Js.nullable
Local alias for 'a Js.nullable
val return : 'a -> 'a t
Constructs a value of 'a Js.nullable
containing a value of 'a
val isNullable : 'a t -> bool
Returns true
if the given value is null
or undefined
, false
otherwise
val null : 'a t
The null
value of type 'a Js.nullable
val undefined : 'a t
The undefined
value of type 'a Js.nullable
Binds the contained value using the given function
If 'a Js.nullable
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.nullable
let maybeGreetWorld (maybeGreeting: string Js.nullable) =
Js.Nullable.bind maybeGreeting ~f:(fun greeting -> greeting ^ " world!")
val iter : f:('a -> unit) Js.Fn.arity1 -> 'a t -> unit
Iterates over the contained value with the given function
If 'a Js.nullable
contains a value, that value is unwrapped and applied to the given function.
let maybeSay (maybeMessage: string Js.nullable) =
Js.Nullable.iter maybeMessage ~f:(fun message -> Js.log message)
val fromOption : 'a option -> 'a t
Maps 'a option
to 'a Js.nullable
Some a | -> | return a |
None | -> | undefined |
val toOption : 'a t -> 'a option
Maps 'a Js.nullable
to 'a option
return a | -> | Some a |
undefined | -> | None |
null | -> | None |