is v1.0.0 Is.Validators.List View Source

Validation for list.

Examples

iex> Is.validate([], :list)
[]

iex> Is.validate([], list: false)
[{:error, [], "must not be a list"}]

iex> Is.validate(["a", "b", "c"], list: :binary)
[]

iex> Is.validate(%{value: ["a", true, "c"]}, map: %{value: [list: [or: [:binary, :boolean]]]})
[]

iex> Is.validate(%{value: ["a", true, 1]}, map: %{value: [list: [or: [:binary, :boolean]]]})
[{:error, [:value, 2], "must satisfies at least one of conditions [:binary, :boolean]"}]

iex> Is.validate(["a", 1, 2], list: [binary: false])
[{:error, [0], "must not be a binary"}]

iex> Is.validate(["a", "b", :c], list: :binary)
[{:error, [2], "must be a binary"}]

iex> Is.validate([%{ok: true}, %{ok: true}, %{ok: false}], list: [map: %{ok: [equals: true]}])
[{:error, [2, :ok], "must equals true"}]

iex> Is.validate("test", unknown: true)
{:error, "Validator :unknown does not exist"}

Link to this section Summary

Link to this section Functions