Tagged

Handle tagged value tuples, such as {:ok, value} and {:error, reason}, in various ways, by constructing macros for the regular matching constructs.

Construct and Destructure

defmodule Tagged.Status
  use Tagged

  deftagged ok
  deftagged error
end

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().

Pipe selective execution

iex> use Tagged.Status
iex> ok(:computer) |> with_ok(& "OK, #{&1}")
"OK, computer"

Installation

If available in Hex, the package can be installed by adding tagged to your list of dependencies in mix.exs:

def deps do
  [
    {:tagged, "~> 0.2.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/tagged.