Lonely v0.3.0 Lonely.Result.List View Source

Functions to operate on result lists.

Link to this section Summary

Functions

Combines a list of results into a result with a list of values. If there is any error, the first is returned

Cons cell

Splits a result list into a list of results

Link to this section Types

Link to this section Functions

Link to this function combine(xs) View Source
combine([t]) :: t

Combines a list of results into a result with a list of values. If there is any error, the first is returned.

iex> import Lonely.Result.List
...> combine([])
{:ok, []}

iex> import Lonely.Result.List
...> combine([{:ok, 1}, {:ok, 2}, {:ok, 3}])
{:ok, [1, 2, 3]}

iex> import Lonely.Result.List
...> combine([{:ok, 1}, {:error, 2}, {:ok, 3}])
{:error, 2}

iex> import Lonely.Result.List
...> combine([{:ok, 1}, {:error, 2}, {:error, 3}])
{:error, 2}

Cons cell.

iex> import Lonely.Result.List
...> cons({:ok, 1}, {:ok, []})
{:ok, [1]}

iex> import Lonely.Result.List
...> cons({:error, :boom}, {:ok, []})
{:error, :boom}

iex> import Lonely.Result.List
...> cons({:ok, 1}, {:error, :boom})
{:error, :boom}

Splits a result list into a list of results.

iex> import Lonely.Result.List
...> split({:ok, []})
[]

iex> import Lonely.Result.List
...> split({:ok, [1]})
[{:ok, 1}]

iex> import Lonely.Result.List
...> split({:ok, [1, 2]})
[{:ok, 1}, {:ok, 2}]

iex> import Lonely.Result.List
...> split({:error, :boom})
{:error, :boom}