and function

Validator and(
  1. Validator validator1,
  2. Validator validator2
)

Passes the test if both of the Validators are valid, and fails if any of them are invalid

In the case that a Validator fails, it's Result will be returned

Implementation

Validator and(Validator validator1, Validator validator2) {
  return (value) {
    final res1 = validator1(value);
    if (res1.isNotValid) return res1;

    final res2 = validator2(value);
    if (res2.isNotValid) return res2;

    return Result.valid;
  };
}