build method
Builds the final validator by composing all chain elements in the correct order.
Build Order:
- Apply prefix transformer (if any)
- Apply coercion with post-validators (if coercion exists)
- 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;
}