sum method

T sum()

Returns the sum of all elements in the collection.

Implementation

T sum() {
  num sum = 0.0;
  for (final current in this) {
    sum += current;
  }
  if (T == int) {
    return sum.toInt() as T;
  } else {
    return sum.toDouble() as T;
  }
}