Talos v1.7.1 Talos.Types.EnumType View Source

Enum type is used to check value to be one of enumerable

For example:

  iex> import Talos
  iex> genders = enum(members: ["male", "female"])
  iex> Talos.valid?(genders, "male")
  true
  iex> Talos.valid?(genders, "female")
  true
  iex> Talos.valid?(genders, "heli")
  false

Also there can be another Talos types:


  iex> digit_string = %Talos.Types.StringType{regexp: ~r/^\d+$/}
  iex> numbers = %Talos.Types.EnumType{members: [digit_string, %Talos.Types.IntegerType{}]}
  iex> Talos.valid?(numbers, "1")
  true
  iex> Talos.valid?(numbers, 1)
  true
  iex> Talos.valid?(numbers, "One")
  false

Additional parameters:

allow_nil - allows value to be nil

members - list of possible values or TalosTypes

Link to this section Summary

Functions

Callback implementation for Talos.Types.errors/2.

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

Link to this section Types

Link to this type

t()

View Source
t() :: %atom(){
  allow_nil: boolean(),
  members: maybe_improper_list(),
  example_value: any()
}

Link to this section Functions

Link to this function

errors(enum_type, value)

View Source

Callback implementation for Talos.Types.errors/2.

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