or method

Validation<T> or(
  1. Validation<T> otherValidation
)

Implementation

Validation<T> or(Validation<T> otherValidation) {
  return Validation(
    (target, package, addViolation) {
      final thisViolations = <String>[];
      final otherViolations = <String>[];
      validation(target, package, thisViolations.add);
      otherValidation(target, package, otherViolations.add);
      final violatesBoth =
          thisViolations.isNotEmpty && otherViolations.isNotEmpty;
      if (violatesBoth) {
        (thisViolations + otherViolations).forEach(addViolation);
      }
    },
    description: '$description OR ${otherValidation.description}',
  );
}