View Source Vx.Literal (Vx v0.1.0)

The Literal type.

Summary

Functions

Builds a new Literal type from a value.

Types

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