Module Js.Undefined
Utility functions on undefined
Provides functionality for dealing with the 'a Js.undefinedJs.undefined('a) type
type +'a t = 'a Js.undefinedtype t(+'a) = Js.undefined('a);Local alias for 'a Js.undefinedJs.undefined('a)
val return : 'a -> 'a tlet return: 'a => t('a);Constructs a value of 'a Js.undefinedJs.undefined('a) containing a value of 'a
val testAny : 'a -> boollet testAny: 'a => bool;Returns true if the given value is empty (undefined)
val empty : 'a tlet empty: t('a);The empty value, undefined
val getUnsafe : 'a t -> 'alet getUnsafe: t('a) => 'a;val getExn : 'a t -> 'alet getExn: t('a) => 'a;val map : f:('a -> 'b) Js.Fn.arity1 -> 'a t -> 'b tlet map: f:Js.Fn.arity1(('a => 'b)) => t('a) => t('b);val bind : f:('a -> 'b t) Js.Fn.arity1 -> 'a t -> 'b tlet bind: f:Js.Fn.arity1(('a => t('b))) => t('a) => t('b);Bind the contained value using the given function
If 'a Js.undefinedJs.undefined('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.undefinedJs.undefined('b)
let maybeGreetWorld (maybeGreeting: string Js.undefined) =
Js.Undefined.bind maybeGreeting ~f:(fun greeting -> greeting ^ " world!")let maybeGreetWorld = (maybeGreeting: Js.undefined(string)) =>
Js.Undefined.bind(maybeGreeting, ~f=greeting => greeting ++ " world!");val iter : f:('a -> unit) Js.Fn.arity1 -> 'a t -> unitlet iter: f:Js.Fn.arity1(('a => unit)) => t('a) => unit;Iterates over the contained value with the given function
If 'a Js.undefinedJs.undefined('a) contains a value, that value is unwrapped and applied to the given function.
let maybeSay (maybeMessage: string Js.undefined) =
Js.Undefined.iter maybeMessage ~f:(fun message -> Js.log message)let maybeSay = (maybeMessage: Js.undefined(string)) =>
Js.Undefined.iter(maybeMessage, ~f=message => Js.log(message));val fromOption : 'a option -> 'a tlet fromOption: option('a) => t('a);Maps 'a optionoption('a) to 'a Js.undefinedJs.undefined('a)
| --- | --- | --- | | Some a | -> | return a | | None | -> | empty |
val toOption : 'a t -> 'a optionlet toOption: t('a) => option('a);Maps 'a Js.undefinedJs.undefined('a) to 'a optionoption('a)
| --- | --- | --- | | return a | -> | Some a | | empty | -> | None |