IterableX<T extends num> extension

Extension on Iterable for numeric types to compute the sum of elements.

Works with both int and double collections. This method will throw a StateError if the iterable is empty, as it relies on reduce.

Example:

final sumInt = [1, 2, 3].sum();
print(sumInt); // 6

final sumDouble = [1.0, 2.0, 3.0].sum();
print(sumDouble); // 6.0
on

Methods

sum() → T

Available on Iterable<T>, provided by the IterableX extension

Returns the sum of all elements in the iterable.