Skip to content

Commit 402e0ed

Browse files
New GroupingMap::fold_in
1 parent 02a2fdc commit 402e0ed

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/grouping_map.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ where
188188
R: Clone,
189189
FO: FnMut(R, &K, V) -> R,
190190
{
191-
self.fold_with(|_, _| init.clone(), operation)
191+
self.fold_in(init, operation, HashMap::new())
192192
}
193193

194194
/// Groups elements from the `GroupingMap` source by key and applies `operation` to the elements
@@ -643,4 +643,15 @@ where
643643
map,
644644
)
645645
}
646+
647+
/// Apply [`fold`](Self::fold) with a provided empty map
648+
/// (`BTreeMap` or `HashMap` with any hasher).
649+
pub fn fold_in<FO, R, M>(self, init: R, operation: FO, map: M) -> M
650+
where
651+
R: Clone,
652+
FO: FnMut(R, &K, V) -> R,
653+
M: Map<Key = K, Value = R>,
654+
{
655+
self.fold_with_in(|_, _| init.clone(), operation, map)
656+
}
646657
}

0 commit comments

Comments
 (0)