Talos.Types.ListType (Talos v1.12.1) View Source

ListType is used to check passed value is a list

  iex> import Talos
  iex> Talos.valid?(list(allow_blank: true), [])
  true
  iex> Talos.valid?(list(allow_nil: true), nil)
  true
  iex> Talos.valid?(list(), nil)
  false
  iex> Talos.valid?(list(), ["one", two, 3, %{}])
  true
  iex> Talos.valid?(list(type: integer()), ["one", two, 3, %{}])
  false
  iex> Talos.valid?(list(type: integer()), [1,2,3])
  true
  iex> Talos.valid?(list(type: integer(allow_nil: true)), [nil,2,3])
  true

Additional parameters:

allow_blank - allows array to be empty

allow_nil - allows value to be nil

type - defines type of array elements

Link to this section Summary

Link to this section Types

Specs

t() :: %{
  __struct__: atom(),
  type: struct() | module() | nil,
  allow_blank: boolean(),
  allow_nil: boolean(),
  example_value: any()
}

Link to this section Functions

Link to this function

errors(array_type, values)

View Source

Specs

errors(t(), any()) :: [String.t()]

Callback implementation for Talos.Types.errors/2.

Specs

permit(t(), any()) :: any()

Specs

valid?(t(), any()) :: boolean()

Callback implementation for Talos.Types.valid?/2.