diff --git a/src/grouping_map.rs b/src/grouping_map.rs index a01968d4a..f165723cc 100644 --- a/src/grouping_map.rs +++ b/src/grouping_map.rs @@ -22,6 +22,7 @@ impl<I, F> MapForGrouping<I, F> { } } +#[allow(clippy::missing_trait_methods)] impl<K, V, I, F> Iterator for MapForGrouping<I, F> where I: Iterator<Item = V>, @@ -32,6 +33,14 @@ where fn next(&mut self) -> Option<Self::Item> { self.0.next().map(|val| ((self.1)(&val), val)) } + + fn fold<B, G>(self, init: B, f: G) -> B + where + G: FnMut(B, Self::Item) -> B, + { + let mut key_mapper = self.1; + self.0.map(|val| (key_mapper(&val), val)).fold(init, f) + } } /// Creates a new `GroupingMap` from `iter`