tagged v0.3.0 Tagged.Status View Source

Resoning in terms of the status of a result.

iex> require Tagged.Status
iex> import Tagged.Status, only: [ok: 1]
iex> ok(:computer)
{:ok, :computer}
iex> with ok(it) <- Keyword.fetch([a: "bacon"], :a), do: "Chunky #{it}!"
"Chunky bacon!"

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

error() :: error(term())

Specs

error(t)

Tagged value tuple with a wrapped type t \\ term()

Specs

ok() :: ok(term())

Specs

ok(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.Status
iex> import Elixir.Tagged.Status
iex> with error(val) <- {:error, :match}, do: val
:match
iex> with error(_) <- {:not_error, :match}, do: true
{:not_error, :match}
Link to this macro

is_error(term)

View Source (macro)

Guard macro for testing if term is a error tagged tuple.

iex> require Elixir.Tagged.Status
iex> import Elixir.Tagged.Status
iex> f = fn x when is_error(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.Status
iex> import Elixir.Tagged.Status
iex> f = fn x when is_ok(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.Status
iex> import Elixir.Tagged.Status
iex> with ok(val) <- {:ok, :match}, do: val
:match
iex> with ok(_) <- {:not_ok, :match}, do: true
{:not_ok, :match}
Link to this macro

with_error(term, f)

View Source (macro)

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.Status
iex> import Elixir.Tagged.Status
iex> {:error, :match} |> with_error(& &1)
:match
iex> {:not_error, :match} |> with_error(& &1)
{:not_error, :match}
Link to this macro

with_ok(term, f)

View Source (macro)

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.Status
iex> import Elixir.Tagged.Status
iex> {:ok, :match} |> with_ok(& &1)
:match
iex> {:not_ok, :match} |> with_ok(& &1)
{:not_ok, :match}