build method

IValidator build()

Builds the final validator by composing all chain elements in the correct order.

Build Order:

  1. Apply prefix transformer (if any)
  2. Apply coercion with post-validators (if coercion exists)
  3. Apply pre-validators (if no coercion or preservation requested)

Implementation

IValidator build() {
  IValidator core;
  // Apply prefix first so coercion sees transformed value.
  IValidator tail() {
    if (_coercion != null) {
      final child = _postValidators ?? Validator.valid;
      final coerced = _coercion!(child);
      // If preserving pre-validators, apply them before coercion
      if (_preservePreValidators && _preValidators != null) {
        return _preValidators! & coerced;
      }
      return coerced;
    }
    return _preValidators ?? Validator.valid;
  }

  core = _prefix != null ? _prefix!(tail()) : tail();
  return core;
}