OkThen.Result.error_consume
You're seeing just the function
error_consume
, go back to OkThen.Result module for more information.
Link to this function
error_consume(result, func_or_value \\ &(&1))
Specs
error_consume(result_input(), (any() -> any())) :: out when out: any()
If result
is tagged with :error
, passes the wrapped value into the provided function (if
provided) and returns :none
.
If result
is not tagged with :error
, result
is returned as-is.
Equivalent to tagged_consume(result, :error, func_or_value)
. See tagged_consume/3
.
Examples
iex> :error |> Result.error_consume()
:none
iex> :error |> Result.error_consume(fn -> "hello" end)
:none
iex> :error |> Result.error_consume(fn {} -> "hello" end)
:none
iex> {:error, 1} |> Result.error_consume(fn 1 -> "hello" end)
:none
iex> {:error, 1, 2} |> Result.error_consume(fn 1, 2 -> "hello" end)
** (ArgumentError) Value-mapping function must have arity between 0 and 1.
iex> {:error, 1, 2} |> Result.error_consume(fn {1, 2} -> "hello" end)
:none
iex> :ok |> Result.error_consume(fn {} -> "hello" end)
:ok
iex> {:ok, 1} |> Result.error_consume(fn 1 -> "hello" end)
{:ok, 1}
iex> "bare value" |> Result.error_consume()
"bare value"