compose static method

allow to compose several validators Note that validator list order is important as first validator failing will return according message.

Implementation

static PhoneNumberInputValidator compose(
  List<PhoneNumberInputValidator> validators,
) {
  return (valueCandidate) {
    for (var validator in validators) {
      final validatorResult = validator.call(valueCandidate);
      if (validatorResult != null) {
        return validatorResult;
      }
    }
    return null;
  };
}