Talos v1.0.4 Talos.Types.ListType View Source

ListType is used to check passed value is a list

  iex> alias Talos.Types.ListType
  iex> alias Talos.Types.IntegerType
  iex> Talos.valid?(%ListType{allow_blank: true}, [])
  true
  iex> Talos.valid?(%ListType{allow_nil: true}, nil)
  true
  iex> Talos.valid?(%ListType{}, nil)
  false
  iex> Talos.valid?(%ListType{}, ["one", two, 3, %{}])
  true
  iex> Talos.valid?(%ListType{type: %IntegerType{}}, ["one", two, 3, %{}])
  false
  iex> Talos.valid?(%ListType{type: %IntegerType{}}, [1,2,3])
  true
  iex> Talos.valid?(%ListType{type: %IntegerType{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

Link to this type

t()

View Source
t() :: %atom(){
  type: struct() | module() | nil,
  allow_blank: boolean(),
  allow_nil: boolean()
}

Link to this section Functions

Link to this function

errors(array_type, values)

View Source
errors(Talos.Types.ListType.t(), any()) :: [String.t()]

Callback implementation for Talos.Types.errors/2.

Link to this function

valid?(list_type, values)

View Source
valid?(Talos.Types.ListType.t(), any()) :: boolean()

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