any<TIn, TOut> static method
ValidateFunc<TIn, TOut>
any<TIn, TOut>(
- List<
LoValidator< validators, [TIn, TOut> > - TOut? defaultError
Checks whether any validator has no error (Like OR).
Returns first error (or defaultError
if not null) otherwise.
Implementation
static ValidateFunc<TIn, TOut> any<TIn, TOut>(
List<LoValidator<TIn, TOut>> validators, [
TOut? defaultError,
]) {
return (input) {
TOut? firstError;
for (final validator in validators) {
final error = validator.validate(input);
if (error == null) {
return null;
} else {
firstError ??= error;
}
}
if (firstError != null) {
return defaultError ?? firstError;
}
return null;
};
}