@@ -220,14 +220,14 @@ where
220
220
///
221
221
/// let lookup = (1..=7)
222
222
/// .into_grouping_map_by(|&n| n % 3)
223
- /// .fold_first (|acc, _key, val| acc + val);
223
+ /// .reduce (|acc, _key, val| acc + val);
224
224
///
225
225
/// assert_eq!(lookup[&0], 3 + 6);
226
226
/// assert_eq!(lookup[&1], 1 + 4 + 7);
227
227
/// assert_eq!(lookup[&2], 2 + 5);
228
228
/// assert_eq!(lookup.len(), 3);
229
229
/// ```
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 >
231
231
where
232
232
FO : FnMut ( V , & K , V ) -> V ,
233
233
{
@@ -239,6 +239,15 @@ where
239
239
} )
240
240
}
241
241
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
+
242
251
/// Groups elements from the `GroupingMap` source by key and collects the elements of each group in
243
252
/// an instance of `C`. The iteration order is preserved when inserting elements.
244
253
///
@@ -321,7 +330,7 @@ where
321
330
where
322
331
F : FnMut ( & K , & V , & V ) -> Ordering ,
323
332
{
324
- self . fold_first ( |acc, key, val| match compare ( key, & acc, & val) {
333
+ self . reduce ( |acc, key, val| match compare ( key, & acc, & val) {
325
334
Ordering :: Less | Ordering :: Equal => val,
326
335
Ordering :: Greater => acc,
327
336
} )
@@ -402,7 +411,7 @@ where
402
411
where
403
412
F : FnMut ( & K , & V , & V ) -> Ordering ,
404
413
{
405
- self . fold_first ( |acc, key, val| match compare ( key, & acc, & val) {
414
+ self . reduce ( |acc, key, val| match compare ( key, & acc, & val) {
406
415
Ordering :: Less | Ordering :: Equal => acc,
407
416
Ordering :: Greater => val,
408
417
} )
@@ -553,7 +562,7 @@ where
553
562
554
563
/// Groups elements from the `GroupingMap` source by key and sums them.
555
564
///
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)`.
557
566
/// It is more limited than `Iterator::sum` since it doesn't use the `Sum` trait.
558
567
///
559
568
/// Returns a `HashMap` associating the key of each group with the sum of that group's elements.
@@ -574,12 +583,12 @@ where
574
583
where
575
584
V : Add < V , Output = V > ,
576
585
{
577
- self . fold_first ( |acc, _, val| acc + val)
586
+ self . reduce ( |acc, _, val| acc + val)
578
587
}
579
588
580
589
/// Groups elements from the `GroupingMap` source by key and multiply them.
581
590
///
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)`.
583
592
/// It is more limited than `Iterator::product` since it doesn't use the `Product` trait.
584
593
///
585
594
/// Returns a `HashMap` associating the key of each group with the product of that group's elements.
@@ -600,6 +609,6 @@ where
600
609
where
601
610
V : Mul < V , Output = V > ,
602
611
{
603
- self . fold_first ( |acc, _, val| acc * val)
612
+ self . reduce ( |acc, _, val| acc * val)
604
613
}
605
614
}
0 commit comments