OkThen.Result.tagged_unwrap_or_else
You're seeing just the function
tagged_unwrap_or_else
, go back to OkThen.Result module for more information.
Link to this function
tagged_unwrap_or_else(result, tag, func_or_value)
Specs
tagged_unwrap_or_else( result_input(), atom(), (atom(), any() -> any()) | (any() -> any()) | any() ) :: any()
Returns the wrapped value if result
is tagged with the specified tag
atom. Otherwise, passes
the tag and wrapped value into the provided function and returns the result. If the function
has arity 1, then only the wrapped value is passed in. An arity-0 function is also accepted. If
func_or_value
is not a function, then it is used directly as the new value.
See also tagged_or_else/3
.
Examples
iex> {:ok, "hello"} |> Result.tagged_unwrap_or_else(:ok, "default")
"hello"
iex> :some |> Result.tagged_unwrap_or_else(:some, "default")
{}
iex> :error |> Result.tagged_unwrap_or_else(:ok, "default")
"default"
iex> {:error, "hello"} |> Result.tagged_unwrap_or_else(:ok, "default")
"default"
iex> {:error, "hello"}
...> |> Result.tagged_unwrap_or_else(:ok, fn
...> :error, "hello" -> "default"
...> end)
"default"
iex> {:error, "hello"}
...> |> Result.tagged_unwrap_or_else(:ok, fn
...> "hello" -> "default"
...> end)
"default"
iex> {:error, "hello"} |> Result.tagged_unwrap_or_else(:ok, fn -> "default" end)
"default"
iex> :none |> Result.tagged_unwrap_or_else(:ok, "default")
"default"
iex> "hello" |> Result.tagged_unwrap_or_else(:ok, "default")
"default"
iex> "hello" |> Result.tagged_unwrap_or_else(:untagged, "default")
"hello"