Tagged
Generates definitions of various things related to tuples with a tagged value,
such as the ubiquitous {:ok, value} and {:error, reason}.
Examples
defmodule Tagged.Status
use Tagged
deftagged ok
deftagged error
end
Construct and Destructure
iex> use Tagged.Status
iex> ok(:computer)
{:ok, :computer}
iex> with error(reason) <- {:ok, :computer}, do: raise reason
{:ok, :computer}
Type definitions
_iex> use Tagged.Status
_iex> t Tagged.Status.error
@type error() :: {:error, term()}
Tagged value tuple, containing term().
Selective execution with unwrapped value
iex> use Tagged.Status
iex> ok(:computer) |> with_ok(& "OK, #{&1}")
"OK, computer"
Installation
The package can be installed by adding tagged to your list of dependencies
in mix.exs:
def deps do
[
{:tagged, "~> 0.3.0"}
]
end