result v0.3.0 Result.Operators

A result operators.

Link to this section Summary

Functions

Return true if result is error

Fold function returns tuple {:ok, [...]} if all tuples in list contain :ok or {:error, ...} if only one tuple contains :error

Map function f to value stored in Ok result

Return true if result is ok

Perform function f on Ok result and return it

Return value if result is ok, otherwise default

Link to this section Functions

Return true if result is error

Examples

iex> Result.Operators.error?({:error, 123}) true

iex> Result.Operators.error?({:ok, 123}) false

Link to this function fold(list, acc \\ [])

Fold function returns tuple {:ok, [...]} if all tuples in list contain :ok or {:error, ...} if only one tuple contains :error.

Examples

iex> val = [{:ok, 3}, {:ok, 5}, {:ok, 12}] iex> Result.Operators.fold(val)

iex> val = [{:ok, 3}, {:error, 1}, {:ok, 2}, {:error, 2}] iex> Result.Operators.fold(val)

Map function f to value stored in Ok result

Examples

iex> ok = {:ok, 3} iex> Result.Operators.map(ok, fn(x) -> x + 10 end)

iex> error = {:error, 3} iex> Result.Operators.map(error, fn(x) -> x + 10 end)

Return true if result is ok

Examples

iex> Result.Operators.ok?({:ok, 123}) true

iex> Result.Operators.ok?({:error, 123}) false

Link to this function perform(result, f)

Perform function f on Ok result and return it

Examples

iex> Result.Operators.perform({:ok, 123}, fn(x) -> x * 100 end)

iex> Result.Operators.perform({:error, 123}, fn(x) -> IO.puts(x) end)

Link to this function with_default(arg, default)

Return value if result is ok, otherwise default

Examples

iex> Result.Operators.with_default({:ok, 123}, 456) 123

iex> Result.Operators.with_default({:error, 123}, 456) 456