monex v0.1.11 MonEx.Option
Option module provides Option type with utility functions.
Link to this section Summary
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()
Link to this section Types
t(a)
t(a) :: {:some, a} | {:none}
t(a) :: {:some, a} | {:none}
Option type.
some(x)
or none()
unwraps into {:some, x}
or {:none}
Link to this section Functions
get(arg)
Returns content of option if argument is some(), raises otherwise
some(5) |> get == 5
get_or_else(arg, f)
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)
Returns true if argument is none()
false if some()
is_none(none()) == true
is_some(arg)
Returns true if argument is some()
false if none()
is_some(some(5)) == true
none() (macro)
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)
some(val) (macro)
to_option(x)
Converts arbitrary term into option, some(term)
if not nil, none()
otherwise
to_option(5) == some(5)
to_option(nil) == none()