API / Js / Js_null_undefined

Js_null_undefined

Contains functionality for dealing with values that can be both null and undefined

t

Local alias for Js.null_undefined('a).

type t<'a> = Js.nullable<'a> = Value('a) | Null | Undefined

return

Constructs a value of Js.null_undefined('a) containing a value of 'a.

let return: 'a => t<'a>

isNullable

Returns true if the given value is null or undefined, false otherwise.

let isNullable: t<'a> => bool

null

The null value of type Js.null_undefined('a).

let null: t<'a>

undefined

The undefined value of type Js.null_undefined('a).

let undefined: t<'a>

bind

Maps the contained value using the given function.

If Js.null_undefined('a) contains a value, that value is unwrapped, mapped to a 'b using the given function a' => 'b, then wrapped back up and returned as Js.null_undefined('b).

RES
let maybeGreetWorld = (maybeGreeting: Js.null_undefined<string>) => Js.Null_undefined.bind(maybeGreeting, (. greeting) => greeting ++ " world!")
let bind: (t<'a>, (. 'a) => 'b) => t<'b>

iter

Iterates over the contained value with the given function. If Js.null_undefined('a) contains a value, that value is unwrapped and applied to the given function.

RES
let maybeSay = (maybeMessage: Js.null_undefined<string>) => Js.Null_undefined.iter(maybeMessage, (. message) => Js.log(message))
let iter: (t<'a>, (. 'a) => unit) => unit

fromOption

Maps option('a) to Js.null_undefined('a). Some(a) => a None => undefined

let fromOption: option<'a> => t<'a>

from_opt

let from_opt: option<'a> => t<'a>

toOption

Maps Js.null_undefined('a) to option('a). a => Some(a) undefined => None null => None

let toOption: t<'a> => option<'a>

to_opt

let to_opt: t<'a> => option<'a>