result v0.3.1 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
Link to this function
error?(arg1)
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)
{:ok, [3, 5, 12]}
iex> val = [{:ok, 3}, {:error, 1}, {:ok, 2}, {:error, 2}]
iex> Result.Operators.fold(val)
{:error, 1}
Link to this function
map(result, f)
Map function f
to value
stored in Ok result
Examples
iex> ok = {:ok, 3}
iex> Result.Operators.map(ok, fn(x) -> x + 10 end)
{:ok, 13}
iex> error = {:error, 3}
iex> Result.Operators.map(error, fn(x) -> x + 10 end)
{:error, 3}
Link to this function
ok?(arg1)
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)
{:ok, 123}
iex> Result.Operators.perform({:error, 123}, fn(x) -> IO.puts(x) end)
{:error, 123}
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