OkThen.Result.tagged_ensure
You're seeing just the function
tagged_ensure
, go back to OkThen.Result module for more information.
Link to this function
tagged_ensure(result, tag, check_function)
Specs
tagged_ensure(result_input(), atom(), (any() -> boolean())) :: result_input()
If result
is tagged with the specified tag
atom, passes the wrapped value into the provided
function. If check_function
returns true
the result
is returned unchanged. Otherwise,
returns :none
.
Examples
iex> {:ok, "hello"} |> Result.tagged_ensure(:ok, &String.length(&1) == 5)
{:ok, "hello"}
iex> {:ok, "hello"} |> Result.tagged_ensure(:ok, &String.length(&1) == 0)
:none
iex> :some |> Result.tagged_ensure(:ok, &String.length(&1) == 0)
:some
iex> :error |> Result.tagged_ensure(:ok, &String.length(&1) == 0)
:error
iex> nil |> Result.tagged_ensure(:ok, &String.length(&1) == 0)
nil