We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b2c108f commit 1da5defCopy full SHA for 1da5def
lib/src/iterable.dart
@@ -353,12 +353,12 @@ extension IterableJoinToString<E> on Iterable<E> {
353
extension IterableSumBy<E> on Iterable<E> {
354
/// Returns the sum of all values produced by [selector] function applied to
355
/// each element in the collection.
356
- double sumBy(num Function(E element) selector) {
357
- var sum = 0.0;
+ T sumBy<T extends num>(T Function(E element) selector) {
+ var sum = T == double ? 0.0 : 0;
358
for (final current in this) {
359
sum += selector(current);
360
}
361
- return sum;
+ return sum as T;
362
363
364
0 commit comments