Option — Optional values

isSome

Returns true if the argument is not null.

isSome : ?Any -> Bool

isNull

Returns true if the argument is null.

isNull : ?Any -> Bool

unwrapOr

Unwraps an optional value, with a default value, i.e. unwrap(?x, d) = x and unwrap(null, d) = d.

unwrapOr : <T> (?T, default : T) -> T

option

Unwraps an optional value using a function, or returns the default, i.e. option(?x, f, d) = f x and option(null, f, d) = d.

option : <A,B>(?A, f : A -> B, default : B) -> B

map

Applies a function to the wrapped value.

map : <A, B>(f: A->B, x: ?A) -> ?B

apply

Applies an optional function to an optional value. Returns null if at least one of the arguments is null.

apply : <A, B>(?(A -> B), ?A) -> ?B

bind

Applies an function to an optional value. Returns null if the argument is null, or the function returns null.

Together with pure, this forms a “monad”.
bind : <A, B>(?A, A -> ?B) -> ?B

join

Given an optional optional value, removes one layer of optionality.

join : <A> ??A -> ?A

pure

Creates an optional value from a definite value.

pure : <A> A -> ?A

assertSome

Asserts that the value is not null; fails otherwise.

assertSome : ?Any -> ()

assertNull

Asserts that the value is null; fails otherwise.

assertNull : ?Any -> ()

unwrap

Unwraps an optional value, i.e. unwrap(?x) = x.

unwrap(x) will fail if the argument is null, and is generally considered bad style. Use switch x instead.
unwrap : <T>?T -> T