sum property

num get sum

Calculates the sum of all elements in the list.

Only works with numeric types (num, int, double). Returns 0 for empty lists or non-numeric types.

Implementation

num get sum {
  if (isEmpty) return 0;
  if (T == int || T == double || T == num) {
    return fold<num>(0, (sum, item) => sum + (item as num));
  }
  return 0;
}