OkThen.Result.unwrap_or_else
You're seeing just the function
unwrap_or_else
, go back to OkThen.Result module for more information.
Link to this function
unwrap_or_else(result, default)
Specs
unwrap_or_else(result_input(), any()) :: any()
Returns the wrapped value if result
is tagged :ok
. 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
.
Equivalent to tagged_unwrap_or_else(result, :ok, default)
. See tagged_unwrap_or_else/3
.
Examples
iex> {:ok, "hello"} |> Result.unwrap_or_else("default")
"hello"
iex> :ok |> Result.unwrap_or_else("default")
{}
iex> :error |> Result.unwrap_or_else("default")
"default"
iex> {:error, "hello"} |> Result.unwrap_or_else("default")
"default"
iex> {:error, "hello"}
...> |> Result.unwrap_or_else(fn
...> :error, "hello" -> "default"
...> end)
"default"
iex> {:error, "hello"}
...> |> Result.unwrap_or_else(fn
...> "hello" -> "default"
...> end)
"default"
iex> {:error, "hello"} |> Result.unwrap_or_else(fn -> "default" end)
"default"
iex> :none |> Result.unwrap_or_else("default")
"default"
iex> "hello" |> Result.unwrap_or_else("default")
"default"