result v0.1.0 Result.Operators
A result operators.
Link to this section Summary
Functions
Map function f
to value
stored in Ok result
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
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)
iex> error = {:error, 3} iex> Result.Operators.map(error, fn(x) -> x + 10 end)
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