cargo fmt the file
use std::collections::HashMap;
use std::hash::Hash;
use std::iter::Iterator;
+use alloc::Vec;
/// Return a `HashMap` of keys mapped to a list of their corresponding values.
///
/// See [`.into_group_map()`](../trait.Itertools.html#method.into_group_map)
/// for more information.
pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
- where I: Iterator<Item=(K, V)>,
+where
+ I: Iterator<Item = (K, V)>,
K: Hash + Eq,
{
let mut lookup = HashMap::new();
@@ -22,7 +24,8 @@ pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
}
pub fn into_group_map_by<I, K, V>(iter: I, f: impl Fn(&V) -> K) -> HashMap<K, Vec<V>>
- where I: Iterator<Item=V>,
+where
+ I: Iterator<Item = V>,
K: Hash + Eq,
{
let mut lookup = HashMap::new();
@@ -35,15 +38,16 @@ pub fn into_group_map_by<I, K, V>(iter: I, f: impl Fn(&V) -> K) -> HashMap<K, Ve
lookup
}
-pub fn into_group_map_by_fold<I, K, V, Acc, Fold>(iter: I, f_key: impl Fn(&V) -> K,
+pub fn into_group_map_by_fold<I, K, V, Acc, Fold>(
+ iter: impl Iterator<Item=V>,
+ f_key: impl Fn(&V) -> K,
init: Acc,
- fold: Fold) -> HashMap<K, Acc>
- where I: Iterator<Item=V>,
+ fold: Fold,
+) -> HashMap<K, Acc>
+where
K: Hash + Eq,
Acc: Clone,
- Fold : FnMut(Acc,V) -> Acc + Clone
-
-
+ Fold: FnMut(Acc, V) -> Acc + Clone,
{
let mut lookup = HashMap::new();
@@ -57,4 +61,3 @@ pub fn into_group_map_by_fold<I, K, V, Acc, Fold>(iter: I, f_key: impl Fn(&V) ->
.map(move |(key, value)| (key, value.into_iter().fold(init.clone(), fold.clone())))
.collect()
}
-
