toNum function
- IValidator child
Coerces a value to a number (num
).
Handles existing numbers (num
) and strings that can be parsed as a number.
Passes the resulting number to the child
validator.
Implementation
IValidator toNum(IValidator child) =>
($isNumber | $isNumString) &
transform((value) {
return switch (value) {
final num n => n,
final String s => num.tryParse(s.trim()),
_ => null,
};
}, child);