Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the closure arguments for reduce. #88928

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down