OkThen.Result.filter
You're seeing just the function
filter
, go back to OkThen.Result module for more information.
Link to this function
filter(result, check_function)
Specs
filter(result_input(), (any() -> as_boolean(any()))) :: result_input()
If result
is tagged :ok
, passes the wrapped value into the provided function. If
check_function
returns a truthy value, result
is returned unchanged. Otherwise, returns
:none
.
Equivalent to tagged_filter(result, :ok, check_function)
. See tagged_filter/3
.
Examples
iex> {:ok, "hello"} |> Result.filter(&String.length(&1) == 5)
{:ok, "hello"}
iex> {:ok, "hello"} |> Result.filter(&String.length(&1) == 0)
:none
iex> :some |> Result.filter(&String.length(&1) == 0)
:some
iex> :error |> Result.filter(&String.length(&1) == 0)
:error
iex> nil |> Result.filter(&String.length(&1) == 0)
nil