Monad.Error
The Error monad.
Allows shortcutting computations in typical Elixir/Erlang style.
Works on values of the form {:error, reason}
| {:ok, value}
. If an error
value is passed to bind it is immediately returned, if an ok value is passed
the value inside the tuple is given to the function passed to bind.
Examples
iex> alias Monad.Error
iex> require Error
iex> Error.m do
...> a <- {:ok, 1}
...> b <- return 2
...> return a + b
...> end
{:ok, 3}
iex> alias Monad.Error
iex> require Error
iex> Error.m do
...> a <- fail "aborted"
...> b <- {:ok, 1}
...> return a + b
...> end
{:error, "aborted"}
Summary
Functions
Bind the value inside Error monad m
to function f
Signal failure, i.e. returns {:error, msg}
Callback implementation for Monad.Pipeline.pipebind/2
Inject x
into a Error monad, i.e. returns {:ok, x}
Types
error_m :: {:error, any} | {:ok, any}
Functions
Bind the value inside Error monad m
to function f
.
Note that the computation shortcircuits if m
is an error
value.
Callback implementation for Monad.Pipeline.pipebind/2
.
Macros
Monad do-notation.
See the Monad
module documentation and the
Monad.Error
module documentation
Pipeline form of the monad.
See Monad
module documentation.