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