View Source Vx.List (Vx v0.3.0)
The List type.
Summary
Functions
Requires the list to have a maximum size.
Requires the list to have a minimum size.
Requires the list to be non-empty.
Requires the list to match the given shape.
Builds a new List type.
Builds a new List type with the given inner type.
Types
@opaque t()
The list type.
Functions
@spec max_size(t(), non_neg_integer()) :: t()
Requires the list to have a maximum size.
@spec min_size(t(), non_neg_integer()) :: t()
Requires the list to have a minimum size.
Requires the list to be non-empty.
Examples
iex> Vx.List.non_empty() |> Vx.validate!([1, 2, 3])
:ok
iex> Vx.List.non_empty() |> Vx.validate!([])
** (Vx.Error) must not be empty
Requires the list to match the given shape.
Examples
iex> Vx.List.shape([Vx.Number.t(), Vx.String.t()]) |> Vx.validate!([123, "foo"])
:ok
iex> Vx.List.shape([Vx.Number.t(), Vx.String.t()]) |> Vx.validate!([123])
** (Vx.Error) must match [number, string]
- element 1 is missing
iex> Vx.List.shape([Vx.Number.t(), Vx.String.t()]) |> Vx.validate!([123, :foo])
** (Vx.Error) must match [number, string]
- element 1: must be a string
@spec size(t(), non_neg_integer()) :: t()
@spec t() :: t()
Builds a new List type.
Examples
iex> Vx.List.t() |> Vx.validate!([1, 2, 3])
:ok
iex> Vx.List.t() |> Vx.validate!("foo")
** (Vx.Error) must be a list
Builds a new List type with the given inner type.
Examples
iex> Vx.List.t(Vx.Number.t()) |> Vx.validate!([1, 2, 3])
:ok
iex> Vx.List.t(Vx.String.t()) |> Vx.validate!("foo")
** (Vx.Error) must be a list
iex> Vx.List.t(Vx.String.t()) |> Vx.validate!(["foo", 2, "bar"])
** (Vx.Error) must be a list<string>
- element 1: must be a string