validateUnitType function
Shortcut for a validator to assert that the data is a unit with a specific type (i.e. distance, force)
Implementation
Validator validateUnitType(UnitType expectedType) {
return validate(
(data) =>
(data is CsafeIntegerWithUnits && data.matchesType(expectedType)),
(data) => (data is CsafeIntegerWithUnits)
? ArgumentError(
"Incorrect Units Provided. Expected units of ${expectedType.toString()}, received units of ${data.unit.unitType}")
: ArgumentError("Provided Data is not a CsafeIntegerWithUnits type"));
}