tagged v0.4.1 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
Functions
Constructor error/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 error/1
.
Guard macro for testing if term
is a ok
tagged tuple,
with constructor ok/1
.
Constructor ok/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 error/1
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(_) <- {:error, 1}, do: true
true
iex> with error(_) <- {:not_error, 1}, do: true
{:not_error, 1}
Guard macro for testing if term
is a error
tagged tuple,
with constructor error/1
.
iex> require Elixir.Tagged.Status
iex> import Elixir.Tagged.Status
iex> f = fn x when is_error(x) -> x; _ -> nil end
iex> error(1) |> f.()
{:error, 1}
iex> {:not_error, 1} |> f.()
nil
Guard macro for testing if term
is a ok
tagged tuple,
with constructor ok/1
.
iex> require Elixir.Tagged.Status
iex> import Elixir.Tagged.Status
iex> f = fn x when is_ok(x) -> x; _ -> nil end
iex> ok(1) |> f.()
{:ok, 1}
iex> {:not_ok, 1} |> f.()
nil
Constructor ok/1
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(_) <- {:ok, 1}, do: true
true
iex> with ok(_) <- {: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.Status
iex> import Elixir.Tagged.Status
iex> {:error, 1}
...> |> with_error(fn _ -> :match end)
:match
iex> {:not_error, :miss} |> with_error(& &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.Status
iex> import Elixir.Tagged.Status
iex> {:ok, 1}
...> |> with_ok(fn _ -> :match end)
:match
iex> {:not_ok, :miss} |> with_ok(& &1)
{:not_ok, :miss}