OkThen.Result.ensure

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

ensure(result, check_function)

Specs

ensure(result_input(), (any() -> boolean())) :: result_input()

If result is tagged :ok, passes the wrapped value into the provided function. If check_function returns true the result is returned unchanged. Otherwise, returns :none.

Equivalent to tagged_ensure(result, :ok, check_function). See tagged_ensure/3.

Examples

iex> {:ok, "hello"} |> Result.ensure(&String.length(&1) == 5)
{:ok, "hello"}

iex> {:ok, "hello"} |> Result.ensure(&String.length(&1) == 0)
:none

iex> :some |> Result.ensure(&String.length(&1) == 0)
:some

iex> :error |> Result.ensure(&String.length(&1) == 0)
:error

iex> nil |> Result.ensure(&String.length(&1) == 0)
nil