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

  1. Mappable
  2. Sequenceable
  3. Unwrappable

Summary

Types

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

t()

Functions

Takes a normal tuple of either {:ok, value} or {:error, value} and turns it into the Result Container

Types

result_tuple()
result_tuple() :: {:ok, any} | {:error, any}

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

t()
t() :: %Containers.Result{value: result_tuple}

Functions

from_tuple(t)
from_tuple(result_tuple) :: t

Takes a normal tuple of either {:ok, value} or {:error, value} and turns it into the Result Container.

Will throw NoMatch error if something other then result_tuple is passed in.

Examples

iex> Containers.Result.from_tuple({:ok, "hello"})
%Containers.Result{value: {:ok, "hello"}}

iex> Containers.Result.from_tuple({:error, "no"})
%Containers.Result{value: {:error, "no"}}