min method Null safety

Value min(
  1. Iterable<Object> arguments
)

Creates a min() 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 min(Iterable<Object> arguments) {
  var args = _simplifyArguments(arguments);
  if (args.isEmpty) {
    throw ArgumentError("min() must have at least one argument.");
  }

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

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