Skip to content

Commit

Permalink
make sumBy generic
Browse files Browse the repository at this point in the history
  • Loading branch information
MohiuddinM committed Mar 26, 2021
1 parent b2c108f commit 1da5def
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/src/iterable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ extension IterableJoinToString<E> on Iterable<E> {
extension IterableSumBy<E> on Iterable<E> {
/// Returns the sum of all values produced by [selector] function applied to
/// each element in the collection.
double sumBy(num Function(E element) selector) {
var sum = 0.0;
T sumBy<T extends num>(T Function(E element) selector) {
var sum = T == double ? 0.0 : 0;
for (final current in this) {
sum += selector(current);
}
return sum;
return sum as T;
}
}

Expand Down

0 comments on commit 1da5def

Please sign in to comment.