sum property
- @useResult
The sum of all elements in this iterable. Returns double.nan if present.
[1, 2, 3].sum; // 6
Implementation
@useResult E get sum {
num sum = 0;
for (final element in this) {
sum += element;
}
// Dart is fucking stupid for not allowing implicit conversions between integers and doubles.
return (E == int ? sum.toInt() : sum.toDouble()) as E;
}