@@ -2466,7 +2466,7 @@ pub trait Itertools: Iterator {
2466
2466
/// - if `f` is a trivial operation like `u32::wrapping_add`, prefer the normal
2467
2467
/// [`Iterator::reduce`] instead since it will most likely result in the generation of simpler
2468
2468
/// code because the compiler is able to optimize it
2469
- /// - otherwise if `f` is non-trivial like `format!`, you should use `tree_fold1 ` since it
2469
+ /// - otherwise if `f` is non-trivial like `format!`, you should use `tree_reduce ` since it
2470
2470
/// reduces the number of operations from `O(n)` to `O(ln(n))`
2471
2471
///
2472
2472
/// Here "non-trivial" means:
@@ -2479,20 +2479,20 @@ pub trait Itertools: Iterator {
2479
2479
///
2480
2480
/// // The same tree as above
2481
2481
/// let num_strings = (1..8).map(|x| x.to_string());
2482
- /// assert_eq!(num_strings.tree_fold1 (|x, y| format!("f({}, {})", x, y)),
2482
+ /// assert_eq!(num_strings.tree_reduce (|x, y| format!("f({}, {})", x, y)),
2483
2483
/// Some(String::from("f(f(f(1, 2), f(3, 4)), f(f(5, 6), 7))")));
2484
2484
///
2485
2485
/// // Like fold1, an empty iterator produces None
2486
- /// assert_eq!((0..0).tree_fold1 (|x, y| x * y), None);
2486
+ /// assert_eq!((0..0).tree_reduce (|x, y| x * y), None);
2487
2487
///
2488
- /// // tree_fold1 matches fold1 for associative operations...
2489
- /// assert_eq!((0..10).tree_fold1 (|x, y| x + y),
2488
+ /// // tree_reduce matches fold1 for associative operations...
2489
+ /// assert_eq!((0..10).tree_reduce (|x, y| x + y),
2490
2490
/// (0..10).fold1(|x, y| x + y));
2491
2491
/// // ...but not for non-associative ones
2492
- /// assert_ne!((0..10).tree_fold1 (|x, y| x - y),
2492
+ /// assert_ne!((0..10).tree_reduce (|x, y| x - y),
2493
2493
/// (0..10).fold1(|x, y| x - y));
2494
2494
/// ```
2495
- fn tree_fold1 < F > ( mut self , mut f : F ) -> Option < Self :: Item >
2495
+ fn tree_reduce < F > ( mut self , mut f : F ) -> Option < Self :: Item >
2496
2496
where
2497
2497
F : FnMut ( Self :: Item , Self :: Item ) -> Self :: Item ,
2498
2498
Self : Sized ,
@@ -2505,7 +2505,7 @@ pub trait Itertools: Iterator {
2505
2505
FF : FnMut ( T , T ) -> T ,
2506
2506
{
2507
2507
// This function could be replaced with `it.next().ok_or(None)`,
2508
- // but half the useful tree_fold1 work is combining adjacent items,
2508
+ // but half the useful tree_reduce work is combining adjacent items,
2509
2509
// so put that in a form that LLVM is more likely to optimize well.
2510
2510
2511
2511
let a = if let Some ( v) = it. next ( ) {
@@ -2555,6 +2555,16 @@ pub trait Itertools: Iterator {
2555
2555
}
2556
2556
}
2557
2557
2558
+ /// See [`.tree_reduce()`](Itertools::tree_reduce).
2559
+ #[ deprecated( note = "Use .tree_reduce() instead" , since = "0.13.0" ) ]
2560
+ fn tree_fold1 < F > ( self , f : F ) -> Option < Self :: Item >
2561
+ where
2562
+ F : FnMut ( Self :: Item , Self :: Item ) -> Self :: Item ,
2563
+ Self : Sized ,
2564
+ {
2565
+ self . tree_reduce ( f)
2566
+ }
2567
+
2558
2568
/// An iterator method that applies a function, producing a single, final value.
2559
2569
///
2560
2570
/// `fold_while()` is basically equivalent to [`Iterator::fold`] but with additional support for
0 commit comments