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