Skip to content

Commit 2cfc868

Browse files
New GroupingMap::sum_in
1 parent 41bdf4b commit 2cfc868

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/grouping_map.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ where
534534
where
535535
V: Add<V, Output = V>,
536536
{
537-
self.reduce(|acc, _, val| acc + val)
537+
self.sum_in(HashMap::new())
538538
}
539539

540540
/// Groups elements from the `GroupingMap` source by key and multiply them.
@@ -760,4 +760,13 @@ where
760760
{
761761
self.minmax_by_in(|key, v1, v2| f(key, v1).cmp(&f(key, v2)), map)
762762
}
763+
764+
/// Apply [`sum`](Self::sum) with a provided map.
765+
pub fn sum_in<M>(self, map: M) -> M
766+
where
767+
V: Add<V, Output = V>,
768+
M: Map<Key = K, Value = V>,
769+
{
770+
self.reduce_in(|acc, _, val| acc + val, map)
771+
}
763772
}

0 commit comments

Comments
 (0)