Skip to content

Commit 5b6285e

Browse files
authored
Rollup merge of rust-lang#88928 - lefth:master, r=Mark-Simulacrum
Document the closure arguments for `reduce`. See issue rust-lang#88927.
2 parents 14eb87d + 6b7f916 commit 5b6285e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/core/src/iter/traits/iterator.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2172,8 +2172,9 @@ pub trait Iterator {
21722172
/// If the iterator is empty, returns [`None`]; otherwise, returns the
21732173
/// result of the reduction.
21742174
///
2175+
/// The reducing function is a closure with two arguments: an 'accumulator', and an element.
21752176
/// For iterators with at least one element, this is the same as [`fold()`]
2176-
/// with the first element of the iterator as the initial value, folding
2177+
/// with the first element of the iterator as the initial accumulator value, folding
21772178
/// every subsequent element into it.
21782179
///
21792180
/// [`fold()`]: Iterator::fold
@@ -2187,8 +2188,8 @@ pub trait Iterator {
21872188
/// where I: Iterator,
21882189
/// I::Item: Ord,
21892190
/// {
2190-
/// iter.reduce(|a, b| {
2191-
/// if a >= b { a } else { b }
2191+
/// iter.reduce(|accum, item| {
2192+
/// if accum >= item { accum } else { item }
21922193
/// })
21932194
/// }
21942195
/// let a = [10, 20, 5, -23, 0];

0 commit comments

Comments
 (0)