Talos v1.4.0 Talos.Types.EnumType View Source
Enum type is used to check value to be one of enumerable
For example:
iex> genders = %Talos.Types.EnumType{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 Sourcet() :: %atom(){ allow_nil: boolean(), members: maybe_improper_list(), example_value: any() }
Link to this section Functions
Callback implementation for Talos.Types.errors/2
.
Link to this function
valid?(type, value)
View Sourcevalid?(Talos.Types.EnumType.t(), any()) :: boolean()
Callback implementation for Talos.Types.valid?/2
.