tagged v0.3.0 Tagged View Source

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> require Tagged.Status, as: Status
iex> Status.ok(:computer)
{:ok, :computer}
iex> with Status.error(reason) <- {:ok, :computer}, do: raise reason
{:ok, :computer}

See Tagged.Constructor for further details.

Type definitions

_iex> t Tagged.Status.error
@type error() :: {:error, term()}

Tagged value tuple, containing term().

See Tagged.Typedef for further details.

Pipe selective execution

iex> require Tagged.Status
iex> import Tagged.Status, only: [ok: 1, with_ok: 2]
iex> ok(:computer) |> with_ok(& "OK, #{&1}")
"OK, computer"

See Tagged.PipeWith for further details.

Link to this section Summary

Functions

Generates a macro that definies all things related to a tagged value tuple, {atom(), term()}. By default the macro has the same name as the tag, and all the things are generated.

Link to this section Functions

Link to this macro

deftagged(tag, opts \\ [])

View Source (macro) (since 0.1.0)

Generates a macro that definies all things related to a tagged value tuple, {atom(), term()}. By default the macro has the same name as the tag, and all the things are generated.

Keywords