Funx.Validator.Each (funx v0.8.4)
View SourceValidates that every element in a list passes a given validator (or validators).
Each provides universal quantification over list elements. It applies one or more
validators to each element and collects all errors using applicative semantics.
Options
Exactly one of the following must be provided:
:validator- A single validator to apply to each element:validators- A list of validators; each element must pass all of them
Each validator may be:
- A validator module implementing
Funx.Validate.Behaviour - A
{Validator, opts}tuple for optioned validators - A validator function with arity 1, 2, or 3
Semantics
- Uses
traverse_afor applicative error collection (all failures reported) - Empty lists pass validation (vacuous truth)
Nothingpasses through unchangedJust(list)unwraps and validates the list
Examples
iex> Funx.Validator.Each.validate([1, 2, 3], validator: Funx.Validator.Positive)
%Funx.Monad.Either.Right{right: [1, 2, 3]}
iex> Funx.Validator.Each.validate([1, 2, 3], validators: [Funx.Validator.Positive, Funx.Validator.Integer])
%Funx.Monad.Either.Right{right: [1, 2, 3]}