sum method

T 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

T sum() {
  var sum = (T == int ? 0 : 0.0) as T;
  for (var current in this) {
    if (current != null) {
      sum = (sum + current) as T;
    }
  }
  return sum;
}