Result.Calc (result v1.7.2)

Result calculations

Link to this section Summary

Functions

Calculate product of Results

Calculate the AND of two results

Calculate the OR of two results

Calculate sum of Results

Link to this section Functions

Specs

product([Result.t(any(), any())]) :: Result.t([...], [...])

Calculate product of Results

product :: List (Result e a) -> Result (List e) (List a)

Examples

iex> data = [{:ok, 1}, {:ok, 2}, {:ok, 3}]
iex> Result.Calc.product(data)
{:ok, [1, 2, 3]}

iex> data = [{:error, 1}, {:ok, 2}, {:error, 3}]
iex> Result.Calc.product(data)
{:error, [1, 3]}

iex> data = [{:error, 1}]
iex> Result.Calc.product(data)
{:error, [1]}

iex> data = []
iex> Result.Calc.product(data)
{:ok, []}
Link to this function

r_and(arg1, arg2)

Specs

r_and(Result.t(any(), any()), Result.t(any(), any())) :: Result.t([...], [...])

Calculate the AND of two results

r_and :: Result e1 a -> Result e2 b -> Result [e1, e2] [a, b]

Examples

iex> Result.Calc.r_and({:ok, 1}, {:ok, 2})
{:ok, [1, 2]}

iex> Result.Calc.r_and({:ok, 1}, {:error, 2})
{:error, [2]}

iex> Result.Calc.r_and({:error, 1}, {:ok, 2})
{:error, [1]}

iex> Result.Calc.r_and({:error, 1}, {:error, 2})
{:error, [1, 2]}
Link to this function

r_or(arg1, arg2)

Specs

r_or(Result.t(any(), any()), Result.t(any(), any())) :: Result.t([...], [...])

Calculate the OR of two results

r_or :: Result e1 a -> Result e2 b -> Result [e1, e2] [a, b]

Examples

iex> Result.Calc.r_or({:ok, 1}, {:ok, 2})
{:ok, [1, 2]}

iex> Result.Calc.r_or({:ok, 1}, {:error, 2})
{:ok, [1]}

iex> Result.Calc.r_or({:error, 1}, {:ok, 2})
{:ok, [2]}

iex> Result.Calc.r_or({:error, 1}, {:error, 2})
{:error, [1, 2]}

Specs

sum([Result.t(any(), any())]) :: Result.t([...], [...])

Calculate sum of Results

sum :: List (Result e a) -> Result (List e) (List a)

Examples

iex> data = [{:ok, 1}, {:ok, 2}, {:ok, 3}]
iex> Result.Calc.sum(data)
{:ok, [1, 2, 3]}

iex> data = [{:error, 1}, {:ok, 2}, {:error, 3}]
iex> Result.Calc.sum(data)
{:ok, [2]}

iex> data = [{:error, 1}, {:error, 2}, {:error, 3}]
iex> Result.Calc.sum(data)
{:error, [1, 2, 3]}

iex> data = [{:error, 1}]
iex> Result.Calc.sum(data)
{:error, [1]}

iex> data = []
iex> Result.Calc.sum(data)
{:error, []}