Skip to content

Commit cb72ea1

Browse files
New GroupingMap::fold_in
1 parent fc2fcb7 commit cb72ea1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/grouping_map.rs

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

195195
/// Groups elements from the `GroupingMap` source by key and applies `operation` to the elements
@@ -641,4 +641,14 @@ where
641641
map,
642642
)
643643
}
644+
645+
/// Apply [`fold`](Self::fold) with a provided map.
646+
pub fn fold_in<FO, R, M>(self, init: R, operation: FO, map: M) -> M
647+
where
648+
R: Clone,
649+
FO: FnMut(R, &K, V) -> R,
650+
M: Map<Key = K, Value = R>,
651+
{
652+
self.fold_with_in(|_, _| init.clone(), operation, map)
653+
}
644654
}

0 commit comments

Comments
 (0)