toDouble function

IValidator toDouble(
  1. IValidator child
)

Coerces a value to a double.

Handles existing doubles, integers (by converting), and strings that can be parsed as a double. Passes the resulting double to the child validator.

Implementation

IValidator toDouble(IValidator child) =>
    ($isDouble | $isNumber | $isDoubleString) &
    transform((v) {
      return switch (v) {
        final double i => i,
        final int i => i.toDouble(),
        final String s => double.tryParse(s.trim()),
        _ => null,
      };
    }, child);