View Source Vx.Tuple (Vx v0.1.0)
The Tuple type.
Summary
Functions
Requires a tuple to match a specific shape.
Requires a tuple to have a specific size.
Builds a new Tuple type.
Types
@opaque t()
The tuple type.
Functions
Requires a tuple to match a specific shape.
Examples
iex> Vx.Tuple.shape({:foo, :bar}) |> Vx.validate!({:foo, :bar})
:ok
iex> Vx.Tuple.shape({Vx.Atom.t(), Vx.String.t()}) |> Vx.validate!({:ok, "result"})
:ok
iex> Vx.Tuple.shape({Vx.Atom.t(), Vx.String.t()}) |> Vx.validate!({:ok, 123})
** (Vx.Error) must match {atom, string}
- element 1: must be a string
@spec size(t(), non_neg_integer()) :: t()
Requires a tuple to have a specific size.
Examples
iex> Vx.Tuple.t() |> Vx.Tuple.size(2) |> Vx.validate!({:foo, :bar})
:ok
iex> Vx.Tuple.t() |> Vx.Tuple.size(2) |> Vx.validate!({:foo})
** (Vx.Error) must have a size of 2
@spec t() :: t()
Builds a new Tuple type.
Examples
iex> Vx.Tuple.t() |> Vx.validate!({:foo, :bar})
:ok
iex> Vx.Tuple.t() |> Vx.validate!(123)
** (Vx.Error) must be a tuple