@@ -2466,7 +2466,7 @@ pub trait Itertools: Iterator {
24662466 /// - if `f` is a trivial operation like `u32::wrapping_add`, prefer the normal
24672467 /// [`Iterator::reduce`] instead since it will most likely result in the generation of simpler
24682468 /// 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
24702470 /// reduces the number of operations from `O(n)` to `O(ln(n))`
24712471 ///
24722472 /// Here "non-trivial" means:
@@ -2479,20 +2479,20 @@ pub trait Itertools: Iterator {
24792479 ///
24802480 /// // The same tree as above
24812481 /// 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)),
24832483 /// Some(String::from("f(f(f(1, 2), f(3, 4)), f(f(5, 6), 7))")));
24842484 ///
24852485 /// // 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);
24872487 ///
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),
24902490 /// (0..10).fold1(|x, y| x + y));
24912491 /// // ...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),
24932493 /// (0..10).fold1(|x, y| x - y));
24942494 /// ```
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 >
24962496 where
24972497 F : FnMut ( Self :: Item , Self :: Item ) -> Self :: Item ,
24982498 Self : Sized ,
@@ -2505,7 +2505,7 @@ pub trait Itertools: Iterator {
25052505 FF : FnMut ( T , T ) -> T ,
25062506 {
25072507 // 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,
25092509 // so put that in a form that LLVM is more likely to optimize well.
25102510
25112511 let a = if let Some ( v) = it. next ( ) {
@@ -2555,6 +2555,16 @@ pub trait Itertools: Iterator {
25552555 }
25562556 }
25572557
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+
25582568 /// An iterator method that applies a function, producing a single, final value.
25592569 ///
25602570 /// `fold_while()` is basically equivalent to [`Iterator::fold`] but with additional support for
0 commit comments