View Source Reather.Either (reather_lite v0.1.2)

Link to this section Summary

Functions

Convert the value with ok or error tuple.

Link to this section Functions

Convert the value with ok or error tuple.

examples

Examples

iex> Reather.Either.new(:ok)
{:ok, nil}
iex> Reather.Either.new(:error)
{:error, nil}
iex> Reather.Either.new({:ok, 3})
{:ok, 3}
iex> Reather.Either.new({:error, "error!"})
{:error, "error!"}
iex> Reather.Either.new({:ok, 1, 2})
{:ok, {1, 2}}
iex> Reather.Either.new({:error, "error", :invalid})
{:error, {"error", :invalid}}
iex> Reather.Either.new({1, 2})
{:ok, {1, 2}}
iex> Reather.Either.new({})
{:ok, {}}
iex> Reather.Either.new(1)
{:ok, 1}
iex> [1, :error]
...> |> Enum.map(fn x ->
...>   Reather.Either.new(x, "error")
...> end)
[{:ok, 1}, {:error, "error"}]