@@ -2028,7 +2028,8 @@ pub trait Iterator {
2028
2028
self . try_fold ( ( ) , call ( f) )
2029
2029
}
2030
2030
2031
- /// An iterator method that applies a function, producing a single, final value.
2031
+ /// Folds every element into an accumulator by applying an operation,
2032
+ /// returning the final result.
2032
2033
///
2033
2034
/// `fold()` takes two arguments: an initial value, and a closure with two
2034
2035
/// arguments: an 'accumulator', and an element. The closure returns the value that
@@ -2049,6 +2050,9 @@ pub trait Iterator {
2049
2050
/// may not terminate for infinite iterators, even on traits for which a
2050
2051
/// result is determinable in finite time.
2051
2052
///
2053
+ /// Note: [`reduce()`] can be used to use the first element as the initial
2054
+ /// value, if the accumulator type and item type is the same.
2055
+ ///
2052
2056
/// # Note to Implementors
2053
2057
///
2054
2058
/// Several of the other (forward) methods have default implementations in
@@ -2104,6 +2108,8 @@ pub trait Iterator {
2104
2108
/// // they're the same
2105
2109
/// assert_eq!(result, result2);
2106
2110
/// ```
2111
+ ///
2112
+ /// [`reduce()`]: Iterator::reduce
2107
2113
#[ doc( alias = "reduce" ) ]
2108
2114
#[ doc( alias = "inject" ) ]
2109
2115
#[ inline]
@@ -2120,10 +2126,15 @@ pub trait Iterator {
2120
2126
accum
2121
2127
}
2122
2128
2123
- /// The same as [`fold()`], but uses the first element in the
2124
- /// iterator as the initial value, folding every subsequent element into it.
2125
- /// If the iterator is empty, return [`None`]; otherwise, return the result
2126
- /// of the fold.
2129
+ /// Reduces the elements to a single one, by repeatedly applying a reducing
2130
+ /// operation.
2131
+ ///
2132
+ /// If the iterator is empty, returns [`None`]; otherwise, returns the
2133
+ /// result of the reduction.
2134
+ ///
2135
+ /// For iterators with at least one element, this is the same as [`fold()`]
2136
+ /// with the first element of the iterator as the initial value, folding
2137
+ /// every subsequent element into it.
2127
2138
///
2128
2139
/// [`fold()`]: Iterator::fold
2129
2140
///
0 commit comments