View Source Reather (reather_lite v0.2.3)

Reather is the combined form of Reader and Either monad. A Reather wrapps an environment and the child functions can use the environment to access the values.

The evaluation of Reather is lazy, so it's never computed until explicitly call Reather.run/2.

Link to this section Summary

Functions

Get the current environment.

Inspect the reather.

Map a function to the reather.

Create a new Reather from the function.

Create a Reather from the value.

Run the reather.

Transform a list of reathers to an reather of a list.

Create a Reather from the value. If the value is Reather, it will be returned as is.

Link to this section Functions

Get the current environment.

Inspect the reather.

Warning: It runs the reather. So, the provided reather should not have side effects.

Map a function to the reather.

map is lazy, so it's never computed until explicitly call Reather.run/2.

examples

Examples

iex> r = reather do
...>       x <- {:ok, 1}
...>       x
...>     end
iex> r
...> |> Reather.map(fn x -> x + 1 end)
...> |> Reather.run()
{:ok, 2}

Create a new Reather from the function.

Create a Reather from the value.

Link to this function

run(reather, arg \\ %{})

View Source

Run the reather.

Transform a list of reathers to an reather of a list.

This operation is lazy, so it's never computed until explicitly call Reather.run/2.

examples

Examples

iex> r = [{:ok, 1}, {:ok, 2}, {:ok, 3}]
...>     |> Enum.map(&Reather.of/1)
...>     |> Reather.traverse()
iex> Reather.run(r)
{:ok, [1, 2, 3]}

iex> r = [{:ok, 1}, {:error, "error"}, {:ok, 3}]
...>     |> Enum.map(&Reather.of/1)
...>     |> Reather.traverse()
iex> Reather.run(r)
{:error, "error"}

Create a Reather from the value. If the value is Reather, it will be returned as is.

examples

Examples

iex> %Reather{} = Reather.wrap(:ok)

iex> r = %Reather{}
iex> ^r = Reather.wrap(r)