View Source Vx.Literal (Vx v0.4.0)
The Literal type.
Summary
Types
@opaque t(value)
Functions
@spec t(value) :: t(value) when value: var
Builds a new Literal type from a value.
Examples
iex> Vx.Literal.t(:foo) |> Vx.validate!(:foo)
:ok
iex> Vx.Literal.t(:foo) |> Vx.validate!(:bar)
** (Vx.Error) must be :foo
Note that everything not being a type (to be precise anything not implementing
the Vx.Validatable
protocol) is automatically considered a literal. So this
is equivalent to the previous example:
iex> :foo |> Vx.validate!(:foo)
:ok
iex> :foo |> Vx.validate!(:bar)
** (Vx.Error) must be :foo