OkThen.Result.default_error

You're seeing just the function default_error, go back to OkThen.Result module for more information.
Link to this function

default_error(result, func_or_value)

Specs

default_error(input, (() -> out) | out) :: input | :error | error(out)
when input: result_input(), out: any()

If result is tagged :none, returns func_or_value wrapped as an :error result. Otherwise, returns result. If func_or_value is a function, the returned value is used as the new value.

If the new value is nil, then the result will remain :none. Consider using none_then/2 if you don't want this behaviour.

If result is not tagged :none, result is returned as-is.

Equivalent to default_as(result, :error, func_or_value). See default_as/3.

Examples

iex> :none |> Result.default_error("hello")
{:error, "hello"}

iex> :none |> Result.default_error({})
:error

iex> :none |> Result.default_error(nil)
:none

iex> :none |> Result.default_error(fn -> 1 end)
{:error, 1}

iex> :none |> Result.default_error(fn {} -> 1 end)
{:error, 1}

iex> {:none, 1} |> Result.default_error(& &1)
{:error, 1}

iex> :error |> Result.default_error("hello")
:error

iex> {:error, 1} |> Result.default_error("hello")
{:error, 1}

iex> {:error, 1, 2} |> Result.default_error("hello")
{:error, 1, 2}

iex> {:anything, 1} |> Result.default_error("hello")
{:anything, 1}

iex> "bare value" |> Result.default_error("hello")
"bare value"