@@ -220,14 +220,14 @@ where
220220 ///
221221 /// let lookup = (1..=7)
222222 /// .into_grouping_map_by(|&n| n % 3)
223- /// .fold_first (|acc, _key, val| acc + val);
223+ /// .reduce (|acc, _key, val| acc + val);
224224 ///
225225 /// assert_eq!(lookup[&0], 3 + 6);
226226 /// assert_eq!(lookup[&1], 1 + 4 + 7);
227227 /// assert_eq!(lookup[&2], 2 + 5);
228228 /// assert_eq!(lookup.len(), 3);
229229 /// ```
230- pub fn fold_first < FO > ( self , mut operation : FO ) -> HashMap < K , V >
230+ pub fn reduce < FO > ( self , mut operation : FO ) -> HashMap < K , V >
231231 where
232232 FO : FnMut ( V , & K , V ) -> V ,
233233 {
@@ -239,6 +239,15 @@ where
239239 } )
240240 }
241241
242+ /// See [`.reduce()`](GroupingMap::reduce).
243+ #[ deprecated( note = "Use .reduce() instead" , since = "0.13.0" ) ]
244+ pub fn fold_first < FO > ( self , operation : FO ) -> HashMap < K , V >
245+ where
246+ FO : FnMut ( V , & K , V ) -> V ,
247+ {
248+ self . reduce ( operation)
249+ }
250+
242251 /// Groups elements from the `GroupingMap` source by key and collects the elements of each group in
243252 /// an instance of `C`. The iteration order is preserved when inserting elements.
244253 ///
@@ -321,7 +330,7 @@ where
321330 where
322331 F : FnMut ( & K , & V , & V ) -> Ordering ,
323332 {
324- self . fold_first ( |acc, key, val| match compare ( key, & acc, & val) {
333+ self . reduce ( |acc, key, val| match compare ( key, & acc, & val) {
325334 Ordering :: Less | Ordering :: Equal => val,
326335 Ordering :: Greater => acc,
327336 } )
@@ -402,7 +411,7 @@ where
402411 where
403412 F : FnMut ( & K , & V , & V ) -> Ordering ,
404413 {
405- self . fold_first ( |acc, key, val| match compare ( key, & acc, & val) {
414+ self . reduce ( |acc, key, val| match compare ( key, & acc, & val) {
406415 Ordering :: Less | Ordering :: Equal => acc,
407416 Ordering :: Greater => val,
408417 } )
@@ -553,7 +562,7 @@ where
553562
554563 /// Groups elements from the `GroupingMap` source by key and sums them.
555564 ///
556- /// This is just a shorthand for `self.fold_first (|acc, _, val| acc + val)`.
565+ /// This is just a shorthand for `self.reduce (|acc, _, val| acc + val)`.
557566 /// It is more limited than `Iterator::sum` since it doesn't use the `Sum` trait.
558567 ///
559568 /// Returns a `HashMap` associating the key of each group with the sum of that group's elements.
@@ -574,12 +583,12 @@ where
574583 where
575584 V : Add < V , Output = V > ,
576585 {
577- self . fold_first ( |acc, _, val| acc + val)
586+ self . reduce ( |acc, _, val| acc + val)
578587 }
579588
580589 /// Groups elements from the `GroupingMap` source by key and multiply them.
581590 ///
582- /// This is just a shorthand for `self.fold_first (|acc, _, val| acc * val)`.
591+ /// This is just a shorthand for `self.reduce (|acc, _, val| acc * val)`.
583592 /// It is more limited than `Iterator::product` since it doesn't use the `Product` trait.
584593 ///
585594 /// Returns a `HashMap` associating the key of each group with the product of that group's elements.
@@ -600,6 +609,6 @@ where
600609 where
601610 V : Mul < V , Output = V > ,
602611 {
603- self . fold_first ( |acc, _, val| acc * val)
612+ self . reduce ( |acc, _, val| acc * val)
604613 }
605614}
0 commit comments