setTransform method
void
setTransform(
- CoercionKind kind,
- IValidator transformer(
- IValidator child
- bool dropPre = true,
Sets a type coercion transformer with optional pre-validator preservation.
Composition Rules:
- First coercion: Sets the coercion and optionally drops pre-validators
- Subsequent coercions: If either is custom, composes them; otherwise replaces
Implementation
void setTransform(
CoercionKind kind,
IValidator Function(IValidator child) transformer, {
bool dropPre = true,
}) {
if (_coercionKind == null) {
// First pivot: drop pre validators (they targeted old domain)
_coercionKind = kind;
_coercion = transformer;
_preservePreValidators = !dropPre;
if (dropPre) _preValidators = null;
return;
}
// Subsequent pivot: compose if either current or previous is custom; replace only if both are built-in
if (kind == CoercionKind.custom || _coercionKind == CoercionKind.custom) {
final previous = _coercion!;
_coercion = (child) => previous(transformer(child));
} else {
_coercion = transformer;
}
_coercionKind = kind;
_postValidators = null;
}