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