tagged v0.4.1 Tagged.Outcome View Source
Reasoning in terms of the outcome of an action.
iex> require Tagged.Outcome
iex> import Tagged.Outcome, only: [failure: 1, success: 1]
iex> failure(:is_human)
{:error, :is_human}
iex> with success(it) <- {:ok, "Computer"}, do: "OK, #{it}!"
"OK, Computer!"
Link to this section Summary
Functions
Constructor failure/1
for error
tagged value tuples. Can also be used to destructure tuples.
Guard macro for testing if term
is a error
tagged tuple,
with constructor failure/1
.
Guard macro for testing if term
is a ok
tagged tuple,
with constructor success/1
.
Constructor success/1
for ok
tagged value tuples. Can also be used to destructure tuples.
Calls f/1
with the wrapped value, when term
matches a
error
tagged tuple. When term
does not match, is is
returned as-is.
Calls f/1
with the wrapped value, when term
matches a
ok
tagged tuple. When term
does not match, is is
returned as-is.
Link to this section Types
Link to this section Functions
Constructor failure/1
for error
tagged value tuples. Can also be used to destructure tuples.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> with failure(_) <- {:error, 1}, do: true
true
iex> with failure(_) <- {:not_error, 1}, do: true
{:not_error, 1}
Guard macro for testing if term
is a error
tagged tuple,
with constructor failure/1
.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> f = fn x when is_failure(x) -> x; _ -> nil end
iex> failure(1) |> f.()
{:error, 1}
iex> {:not_error, 1} |> f.()
nil
Guard macro for testing if term
is a ok
tagged tuple,
with constructor success/1
.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> f = fn x when is_success(x) -> x; _ -> nil end
iex> success(1) |> f.()
{:ok, 1}
iex> {:not_ok, 1} |> f.()
nil
Constructor success/1
for ok
tagged value tuples. Can also be used to destructure tuples.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> with success(_) <- {:ok, 1}, do: true
true
iex> with success(_) <- {:not_ok, 1}, do: true
{:not_ok, 1}
Calls f/1
with the wrapped value, when term
matches a
error
tagged tuple. When term
does not match, is is
returned as-is.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> {:error, 1}
...> |> with_failure(fn _ -> :match end)
:match
iex> {:not_error, :miss} |> with_failure(& &1)
{:not_error, :miss}
Calls f/1
with the wrapped value, when term
matches a
ok
tagged tuple. When term
does not match, is is
returned as-is.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> {:ok, 1}
...> |> with_success(fn _ -> :match end)
:match
iex> {:not_ok, :miss} |> with_success(& &1)
{:not_ok, :miss}