containers v0.7.0 Containers.Result View Source
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
- Flattenable
Link to this section Summary
Types
A tuple that follows the {:ok, value}
, {:error, value}
, :ok
, or :error
pattern
Functions
join is usefull when you have a inner value of something like
{:ok, {:ok, value}}
and you want make the inner value {:ok, value}
Takes a value of :ok
, :error
, {:ok, value}
, or {:error, reason}
and
truns it into the Result Container
Link to this section Types
result_value() :: {:ok, any} | {:error, any} | :ok | :error
A tuple that follows the {:ok, value}
, {:error, value}
, :ok
, or :error
pattern
Link to this section Functions
join is usefull when you have a inner value of something like
{:ok, {:ok, value}}
and you want make the inner value {:ok, value}
Examples
iex> outter = Containers.Result.to_result({:ok, {:ok, 1}})
%Containers.Result{value: {:ok, {:ok, 1}}}
iex> Containers.Result.join(outter)
%Containers.Result{value: {:ok, 1}}
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}