applyArithmetic function
Applies an arithmetic operator to two known values: numbers, or
strings for +. Null if they can't be combined.
Implementation
Object? applyArithmetic(String operator, Object? a, Object? b) {
if (operator == '+' && a is String && b is String) return a + b;
if (a is! num || b is! num) return null;
return switch (operator) {
'+' => a + b,
'-' => a - b,
'*' => a * b,
'/' => b == 0 ? null : a / b,
'~/' => b == 0 ? null : a ~/ b,
_ => null,
};
}