bubblewrap v0.2.1 Bubblewrap.Option
Option module provides Option type with utility functions.
Link to this section Summary
Functions
Returns content of option if argument is not nil, raises otherwise
Returns true if argument is nil
Returns true if argument is not nil
Converts an Option into Result if value is present, otherwise returns second
argument wrapped in error()
Returns option if argument is not nil, second argument which has to be option otherwise. Executes function, if it's supplied
Link to this section Types
t(a)
t(a) :: a | nil
t(a) :: a | nil
Option type.
Link to this section Functions
get(x)
Returns content of option if argument is not nil, raises otherwise
Examples
iex> 5 |> get
5
is_none(arg1)
Returns true if argument is nil
Examples
iex> is_none(nil)
true
iex> is_none(5)
false
is_some(arg1)
Returns true if argument is not nil
Examples
iex> is_some(5)
true
iex> is_some(nil)
false
ok_or_else(x, f)
ok_or_else(t(a), err | (() -> err)) :: Bubblewrap.Result.t(a, err)
when a: any(), err: any()
ok_or_else(t(a), err | (() -> err)) :: Bubblewrap.Result.t(a, err) when a: any(), err: any()
Converts an Option into Result if value is present, otherwise returns second
argument wrapped in error()
.
Examples
iex> 5 |> ok_or_else(2)
{:ok, 5} # Essentially ok(5)
...> nil |> ok_or_else(:missing_value)
{:error, :missing_value} # Essentially error(:missing_value)
...> nil |> ok_or_else(fn -> :oh_no end)
{:error, :oh_no}
Returns option if argument is not nil, second argument which has to be option otherwise. Executes function, if it's supplied.
Examples
iex> 5 |> or_else(2)
5
iex> nil |> or_else(2)
2
iex> nil |> or_else(fn -> 1 end)
1