sum method

num sum()

Returns the sum of all elements in the collection.

All elements have to be of type num or null. null elements are not counted.

Implementation

num sum() {
  // There is a bug in the dart lang that neither is int or is int? return
  // true for a generic class with int? at the type.
  num sum = (T is int || T is int? ? 0 : 0.0);
  for (var current in this) {
    if (current != null) {
      sum = (sum + current);
    }
  }
  return sum as num;
}