max method Null safety

Value max(
  1. Iterable<Object> arguments
)

Creates a max() calculation with the given arguments.

Each argument must be either a SassNumber, a SassCalculation, an unquoted SassString, a CalculationOperation, or a CalculationInterpolation. It must be passed at least one argument.

This automatically simplifies the calculation, so it may return a SassNumber rather than a SassCalculation. It throws an exception if it can determine that the calculation will definitely produce invalid CSS.

Implementation

static Value max(Iterable<Object> arguments) {
  var args = _simplifyArguments(arguments);
  if (args.isEmpty) {
    throw ArgumentError("max() must have at least one argument.");
  }

  SassNumber? maximum;
  for (var arg in args) {
    if (arg is! SassNumber ||
        (maximum != null && !maximum.isComparableTo(arg))) {
      maximum = null;
      break;
    } else if (maximum == null || maximum.lessThan(arg).isTruthy) {
      maximum = arg;
    }
  }
  if (maximum != null) return maximum;

  _verifyCompatibleNumbers(args);
  return SassCalculation._("max", args);
}