containers v0.7.1 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

  1. Mappable
  2. Sequenceable
  3. Unwrappable
  4. Flattenable

Link to this section Summary

Types

A tuple that follows the {:ok, value}, {:error, value}, :ok, or :error pattern

t()

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

Link to this type result_value() View Source
result_value() :: {:ok, any} | {:error, any} | :ok | :error

A tuple that follows the {:ok, value}, {:error, value}, :ok, or :error pattern

Link to this type t() View Source
t() :: %Containers.Result{value: result_value}

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}