Skip to content

Commit cad6e3d

Browse files
committed
into_group_map: make code more idiomatic
1 parent d92a05d commit cad6e3d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/group_map.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ where
1313
I: Iterator<Item = (K, V)>,
1414
K: Hash + Eq,
1515
{
16-
let mut lookup = HashMap::new();
17-
18-
iter.for_each(|(key, val)| {
19-
lookup.entry(key).or_insert_with(Vec::new).push(val);
20-
});
21-
22-
lookup
16+
iter.fold(HashMap::new(), |mut acc, (key, val)| {
17+
acc.entry(key).or_default().push(val);
18+
acc
19+
})
2320
}
2421

2522
pub fn into_group_map_by<I, K, V, F>(iter: I, mut f: F) -> HashMap<K, Vec<V>>

0 commit comments

Comments
 (0)