containers v0.5.0 Containers.Result
This container is useful when you want to do chainable maps or sequences on the :ok
:error
tuple
pattern that Elixir uses for actions that could fail.
Implemented Protocols
- Mappable
- Sequenceable
- Unwrappable
Summary
Types
A tuple that follows the {:ok, value}
, {:error, value}
, :ok
, or :error
pattern
Functions
Takes a value of :ok
, :error
, {:ok, value}
, or {:error, reason}
and
truns it into the Result Container
Types
A tuple that follows the {:ok, value}
, {:error, value}
, :ok
, or :error
pattern
Functions
Takes a value of :ok
, :error
, {:ok, value}
, or {:error, reason}
and
truns it into the Result Container
Will throw NoMatch
error if something other then result_value
is
passed in.
Examples
iex> Containers.Result.to_result({:ok, "hello"})
%Containers.Result{value: {:ok, "hello"}}
iex> Containers.Result.to_result({:error, "no"})
%Containers.Result{value: {:error, "no"}}
iex> Containers.Result.to_result(:error)
%Containers.Result{value: :error}
iex> Containers.Result.to_result(:ok)
%Containers.Result{value: :ok}