Rollup merge of #88928 - lefth:master, r=Mark-Simulacrum

Document the closure arguments for `reduce`.

See issue #88927.
This commit is contained in:
Manish Goregaokar 2021-09-16 10:57:20 -07:00 committed by GitHub
commit 5b6285e370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2172,8 +2172,9 @@ pub trait Iterator {
/// If the iterator is empty, returns [`None`]; otherwise, returns the /// If the iterator is empty, returns [`None`]; otherwise, returns the
/// result of the reduction. /// result of the reduction.
/// ///
/// The reducing function is a closure with two arguments: an 'accumulator', and an element.
/// For iterators with at least one element, this is the same as [`fold()`] /// For iterators with at least one element, this is the same as [`fold()`]
/// with the first element of the iterator as the initial value, folding /// with the first element of the iterator as the initial accumulator value, folding
/// every subsequent element into it. /// every subsequent element into it.
/// ///
/// [`fold()`]: Iterator::fold /// [`fold()`]: Iterator::fold
@ -2187,8 +2188,8 @@ pub trait Iterator {
/// where I: Iterator, /// where I: Iterator,
/// I::Item: Ord, /// I::Item: Ord,
/// { /// {
/// iter.reduce(|a, b| { /// iter.reduce(|accum, item| {
/// if a >= b { a } else { b } /// if accum >= item { accum } else { item }
/// }) /// })
/// } /// }
/// let a = [10, 20, 5, -23, 0]; /// let a = [10, 20, 5, -23, 0];