Funx.Validator.NotIn (funx v0.8.2)
View SourceValidates that a value is not a member of a given collection using an Eq
comparator.
NotIn enforces an exclusion constraint of the form:
“value must not be one of these”.
Membership is defined by an Eq instance, not by structural equality or
Elixir’s in operator.
Options
:values(required) The list of disallowed values.:eq(optional) An equality comparator. Defaults toFunx.Eq.Protocol.:message(optional) A custom error message callback(value -> String.t())used to override the default error message on failure.
Semantics
- If the value matches any element in
:valuesunderEq, validation fails. - If the value does not match any element, validation succeeds.
Nothingvalues are preserved and treated as not applicable.Justvalues are unwrapped before comparison.
Examples
iex> Funx.Validator.NotIn.validate("deleted", values: ["active", "inactive"]) %Funx.Monad.Either.Right{right: "deleted"}
iex> Funx.Validator.NotIn.validate("active", values: ["active", "inactive"]) %Funx.Monad.Either.Left{
left: %Funx.Errors.ValidationError{
errors: ["must not be one of: [\"active\", \"inactive\"]"]
}}
iex> Funx.Validator.NotIn.validate(%Funx.Monad.Maybe.Nothing{}, values: ["a", "b"]) %Funx.Monad.Either.Right{right: %Funx.Monad.Maybe.Nothing{}}