Skip to content

Commit c22c475

Browse files
committed
removed into_group_map_by_fold maybe for next.
added documentation for into_group_map_by, added into_group_map_by in the itertools trait.
1 parent a7032f9 commit c22c475

File tree

2 files changed

+95
-75
lines changed

2 files changed

+95
-75
lines changed

src/group_map.rs

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
use std::collections::HashMap;
44
use std::hash::Hash;
55
use std::iter::Iterator;
6-
use alloc::Vec;
6+
use HashMapIntoIter;
77

88
/// Return a `HashMap` of keys mapped to a list of their corresponding values.
99
///
1010
/// See [`.into_group_map()`](../trait.Itertools.html#method.into_group_map)
1111
/// for more information.
1212
pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
13-
where
14-
I: Iterator<Item = (K, V)>,
15-
K: Hash + Eq,
13+
where
14+
I: Iterator<Item=(K, V)>,
15+
K: Hash + Eq,
1616
{
1717
let mut lookup = HashMap::new();
1818

@@ -23,10 +23,10 @@ where
2323
lookup
2424
}
2525

26-
pub fn into_group_map_by<I, K, V>(iter: I, f: impl Fn(&V) -> K) -> HashMap<K, Vec<V>>
27-
where
28-
I: Iterator<Item = V>,
29-
K: Hash + Eq,
26+
pub fn into_group_map_by<I, K, V>(iter: I, f: impl Fn(&V) -> K) ->HashMapIntoIter<K,Vec<V>>
27+
where
28+
I: Iterator<Item=V>,
29+
K: Hash + Eq,
3030
{
3131
let mut lookup = HashMap::new();
3232

@@ -35,29 +35,6 @@ where
3535
lookup.entry(key).or_insert(Vec::new()).push(val);
3636
}
3737

38-
lookup
38+
lookup.into_iter()
3939
}
4040

41-
pub fn into_group_map_by_fold<I, K, V, Acc, Fold>(
42-
iter: impl Iterator<Item=V>,
43-
f_key: impl Fn(&V) -> K,
44-
init: Acc,
45-
fold: Fold,
46-
) -> HashMap<K, Acc>
47-
where
48-
K: Hash + Eq,
49-
Acc: Clone,
50-
Fold: FnMut(Acc, V) -> Acc + Clone,
51-
{
52-
let mut lookup = HashMap::new();
53-
54-
for val in iter {
55-
let key = f_key(&val);
56-
lookup.entry(key).or_insert(Vec::new()).push(val);
57-
}
58-
59-
lookup
60-
.into_iter()
61-
.map(move |(key, value)| (key, value.into_iter().fold(init.clone(), fold.clone())))
62-
.collect()
63-
}

0 commit comments

Comments
 (0)