Talos.Types.EnumType (Talos v1.12.3) 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
Specs
t() :: %{ __struct__: atom(), allow_nil: boolean(), members: maybe_improper_list(), example_value: any() }
Link to this section Functions
Specs
Callback implementation for Talos.Types.errors/2
.
Specs
Specs
Callback implementation for Talos.Types.valid?/2
.