From 6b7f916008f48b9a8635d461dc33f7c5621611a2 Mon Sep 17 00:00:00 2001 From: Dan Zwell Date: Tue, 14 Sep 2021 14:22:49 +0800 Subject: [PATCH] Document the closure arguments for `reduce`. Fixes issue #88927. --- library/core/src/iter/traits/iterator.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 330d3714247c5..b0a9d9f5ef5c9 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -2172,8 +2172,9 @@ pub trait Iterator { /// If the iterator is empty, returns [`None`]; otherwise, returns the /// 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()`] - /// 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. /// /// [`fold()`]: Iterator::fold @@ -2187,8 +2188,8 @@ pub trait Iterator { /// where I: Iterator, /// I::Item: Ord, /// { - /// iter.reduce(|a, b| { - /// if a >= b { a } else { b } + /// iter.reduce(|accum, item| { + /// if accum >= item { accum } else { item } /// }) /// } /// let a = [10, 20, 5, -23, 0];