Witha v0.1.1 Witha.Error View Source

Either monad chain.

The typespec of either is {:ok, term} | {:error, term}.

iex> witha Witha.Error, x1 <- {:ok, 1}, do: x1 + 1
{:ok, 2}

iex> witha Witha.Error, x1 <- {:error, "駄目"}, do: x1
{:error, "駄目"}

:ok can chain.

iex> witha Witha.Error, [
iex>   x1 <- {:ok, 1},
iex>   x2 <- {:ok, x1 + 1},
iex> ], do: x1 + x2
{:ok, 3}

:error & raise stops the chain.

iex> witha Witha.Error, [
iex>   x1 <- {:error, "駄目"},
iex>   x2 <- {:ok, x1 + 1},
iex> ], do: x1 + x2
{:error, "駄目"}

iex> witha Witha.Error, [
iex>   x1 <- raise("駄目"),
iex>   x2 <- {:ok, x1 + 1},
iex> ], do: x1 + x2
{:error, %RuntimeError{message: "駄目"}}

Link to this section Summary

Functions

Callback implementation for c:Witha.Aspect.flat_map/2

Callback implementation for c:Witha.Aspect.handle_error/1

Callback implementation for c:Witha.Aspect.new/1

Link to this section Functions

Callback implementation for c:Witha.Aspect.flat_map/2.

Callback implementation for c:Witha.Aspect.handle_error/1.

Callback implementation for c:Witha.Aspect.new/1.