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
    
      
      Link to this function
    
    
  product(list)
Specs
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
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
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]}
    
      
      Link to this function
    
    
  sum(list)
Specs
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, []}