Js.NullableProvide utilities around null_undefined
Contains functionality for dealing with values that can be both null and undefined
val return : 'a -> 'a tConstructs a value of 'a Js.null_undefined containing a value of 'a
val isNullable : 'a t -> boolReturns true if the given value is null or undefined, false otherwise
val null : 'a tThe null value of type 'a Js.null_undefined
val undefined : 'a tThe undefined value of type 'a Js.null_undefined
val map : f:('a -> 'b) Js.Fn.arity1 -> 'a t -> 'b tval bind : f:('a -> 'b t) Js.Fn.arity1 -> 'a t -> 'b tBinds 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 ~f:(fun greeting -> greeting ^ " world!")val iter : f:('a -> unit) Js.Fn.arity1 -> 'a t -> unitIterates 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 ~f:(fun message -> Js.log message)val fromOption : 'a option -> 'a tMaps 'a option to 'a Js.null_undefined
| Some a | -> | return a |
| None | -> | undefined |
val toOption : 'a t -> 'a optionMaps 'a Js.null_undefined to 'a option
| return a | -> | Some a |
| undefined | -> | None |
| null | -> | None |