when<T, E> static method

Formix<T, E> when<T, E>({
  1. required bool condition(
    1. T value
    ),
  2. required Formix<T, E> then,
  3. Formix<T, E>? orElse,
})

Creates a conditional validator.

If condition returns true, runs then. Otherwise, runs orElse if provided, or returns valid.

final validator = Validate.when<String, String>(
  condition: (value) => value.startsWith('+'),
  then: phoneRule,
  orElse: emailRule,
);

Implementation

static Formix<T, E> when<T, E>({
  required bool Function(T value) condition,
  required Formix<T, E> then,
  Formix<T, E>? orElse,
}) =>
    WhenElse(
      condition: condition,
      thenValidator: then,
      elseValidator: orElse,
    );