OkThen.Result.tagged_assert-exclamation-mark
You're seeing just the function
tagged_assert-exclamation-mark
, go back to OkThen.Result module for more information.
Link to this function
tagged_assert!(result, tag, check_function \\ fn _ -> true end)
Specs
tagged_assert!(result_input(), atom(), (any() -> boolean())) :: result_input()
Raises ArgumentError
if result
is not tagged with the specified tag
atom. Otherwise,
returns result
unchanged. You may optionally provide check_function/1
, which will receive
the unwrapped value and must return a boolean. If the return value is false
the function will
raise.
Examples
iex> {:ok, "hello"} |> Result.tagged_assert!(:ok)
{:ok, "hello"}
iex> {:ok, "hello"} |> Result.tagged_assert!(:ok, &String.length(&1) == 5)
{:ok, "hello"}
iex> {:ok, "hello"} |> Result.tagged_assert!(:ok, &String.length(&1) == 0)
** (ArgumentError) Result value failed assertion: {:ok, "hello"}.
iex> :some |> Result.tagged_assert!(:some)
:some
iex> :error |> Result.tagged_assert!(:ok)
** (ArgumentError) Result is not tagged ok: :error.
iex> {:ok, "hello"} |> Result.tagged_assert!(:error)
** (ArgumentError) Result is not tagged error: {:ok, "hello"}.
iex> :none |> Result.tagged_assert!(:ok)
** (ArgumentError) Result is not tagged ok: :none.
iex> "hello" |> Result.tagged_assert!(:untagged)
"hello"
iex> "hello" |> Result.tagged_assert!(:ok)
** (ArgumentError) Result is not tagged ok: "hello".