sum method

T sum()

Calculates sum of items.

Returns 0 if the iterable is empty.

Implementation

T sum() {
  var result = 0.0;
  for (var item in this) {
    result += item;
  }
  if (result is T) {
    return result as T;
  }
  final resultAsInt = result.toInt();
  if (resultAsInt is T) {
    return resultAsInt as T;
  }
  throw UnsupportedError('Unsupported subtype');
}