Option module

Type definition

import P "prelude";

public type t<A> = ?A;

isSome

Returns true if the value is not null.

public func isSomeAny(x: ?Any): Bool

public func isSome<A>(x: t<A>): Bool

isNull

Returns true if the value is null.

public func isNullAny(x: ?Any): Bool = not isSome<Any>(x);

public func isNull<A>(x: t<A>): Bool = not isSome<A>(x);

unwrap

Unwrap an optional value, and fail if it is null.

public func unwrap<T>(x: ?T): T

unwrapOr

Unwrap an optional value or a default.

public func unwrapOr<T>(x: ?T, d: T): T

option

Unwrap an optional value. If null, return the default, else, apply the function to the unwrapped value.

public func option<A, B>(x: ?A, f: A->B, d: B): B

map

Apply a function to the wrapped value.

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

assertSome

Assert that the given value is not null; ignore this value and return unit.

public func assertSomeAny(x: ?Any) : ()
public func assertSome<A>(x: ?A)   : ()

assertNull

Assert that the given value is null; ignore this value and return unit.

public func assertNullAny(x: ?Any) : ()
public func assertNull<A>(x: ?A)   : ()

printOpInt

Print an optional integer.

public func printOpInt(x : ?Int) : ()

apply

public func apply<A, B>(f : ?(A -> B), x : ?A) : ?B

bind

public func bind<A, B>(x : ?A, f : A -> ?B) : ?B

join

public func join<A>(x : ??A) : ?A

pure

public func pure<A>(x: A) : ?A