monex v0.1.10 MonEx.Option

Option module provides Option type with utility functions.

Summary

Types

t()

Option type. some(x) or none() unwraps into {:some, x} or {:none}

Functions

Returns content of option if argument is some(), raises otherwise

some(5) |> get == 5

Returns content of option if argument is some(), second argument otherwise.

some(5) |> get_or_else(2) == 5
none() |> get_or_else(2) == 2
none() |> get_or_else(fn -> 1) == 1

Returns true if argument is none() false if some()

is_none(none()) == true

Returns true if argument is some() false if none()

is_some(some(5)) == true

Returns option if argument is some(), second argument wrapped in some otherwise. Executes function, if it’s supplied.

some(5) |> or_else(2) == some(5)
none() |> or_else(2) == some(2)
none() |> or_else(fn -> some(1)) == some(1)

Converts arbitrary term into option, some(term) if not nil, none() otherwise

to_option(5) == some(5)
to_option(nil) == none()

Types

t()
t() :: {:some, term} | {:none}

Option type. some(x) or none() unwraps into {:some, x} or {:none}

Functions

get(arg)
get(t) :: term

Returns content of option if argument is some(), raises otherwise

some(5) |> get == 5
get_or_else(arg, f)
get_or_else(t, term | (() -> term)) :: term

Returns content of option if argument is some(), second argument otherwise.

some(5) |> get_or_else(2) == 5
none() |> get_or_else(2) == 2
none() |> get_or_else(fn -> 1) == 1
is_none(x)
is_none(t) :: boolean

Returns true if argument is none() false if some()

is_none(none()) == true
is_some(arg)
is_some(t) :: boolean

Returns true if argument is some() false if none()

is_some(some(5)) == true
or_else(x, f)
or_else(t, term | (() -> t)) :: t

Returns option if argument is some(), second argument wrapped in some otherwise. Executes function, if it’s supplied.

some(5) |> or_else(2) == some(5)
none() |> or_else(2) == some(2)
none() |> or_else(fn -> some(1)) == some(1)
to_option(x)
to_option(term) :: t

Converts arbitrary term into option, some(term) if not nil, none() otherwise

to_option(5) == some(5)
to_option(nil) == none()

Macros

none()
some(val)