tagged v0.3.0 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
Types
Tagged value tuple with a wrapped type t
\\ term()
Tagged value tuple with a wrapped type t
\\ term()
Functions
Constructor for error
tagged value tuples. Can also be used
to destructure tuples.
Guard macro for testing if term
is a error
tagged tuple.
Guard macro for testing if term
is a ok
tagged tuple.
Constructor 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
Specs
Specs
failure(t)
Tagged value tuple with a wrapped type t
\\ term()
Specs
Specs
success(t)
Tagged value tuple with a wrapped type t
\\ term()
Link to this section Functions
Constructor 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(val) <- {:error, :match}, do: val
:match
iex> with failure(_) <- {:not_error, :match}, do: true
{:not_error, :match}
Guard macro for testing if term
is a error
tagged tuple.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> f = fn x when is_failure(x) -> x; _ -> nil end
iex> {:error, true} |> f.()
{:error, true}
iex> {:not_error, true} |> f.()
nil
Guard macro for testing if term
is a ok
tagged tuple.
iex> require Elixir.Tagged.Outcome
iex> import Elixir.Tagged.Outcome
iex> f = fn x when is_success(x) -> x; _ -> nil end
iex> {:ok, true} |> f.()
{:ok, true}
iex> {:not_ok, true} |> f.()
nil
Constructor 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(val) <- {:ok, :match}, do: val
:match
iex> with success(_) <- {:not_ok, :match}, do: true
{:not_ok, :match}
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, :match} |> with_failure(& &1)
:match
iex> {:not_error, :match} |> with_failure(& &1)
{:not_error, :match}
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, :match} |> with_success(& &1)
:match
iex> {:not_ok, :match} |> with_success(& &1)
{:not_ok, :match}