From 6655bdd2b33df72aa23e397886717042e5da4334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Mon, 2 Mar 2015 22:31:01 +0100 Subject: [PATCH 1/2] Add description of fold function arguments. --- src/libcore/iter.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 88a729a3db09e..8f24854bcddfd 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -607,20 +607,28 @@ pub trait IteratorExt: Iterator + Sized { /// Performs a fold operation over the entire iterator, returning the /// eventual state at the end of the iteration. /// + /// # Arguments + /// + /// * `init` - initial value for accumulator, it is also returned if iterator is empty + /// * `func(acc, item)` - function applied to the elements + /// + `acc` - accumulator = value returned by last call of `func` (or `init` if it is first + /// call) + /// + `item` - current element + /// /// # Examples /// /// ``` /// let a = [1, 2, 3, 4, 5]; - /// assert!(a.iter().fold(0, |a, &b| a + b) == 15); + /// assert!(a.iter().fold(0, |acc, &item| acc + item) == 15); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn fold(self, init: B, mut f: F) -> B where + fn fold(self, init: B, mut func: F) -> B where F: FnMut(B, Self::Item) -> B, { let mut accum = init; for x in self { - accum = f(accum, x); + accum = func(accum, x); } accum } From c0069307490a9e60a8a4fdbcbac4e605c45c90f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Fri, 6 Mar 2015 12:09:18 +0100 Subject: [PATCH 2/2] Revert controversial changes --- src/libcore/iter.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 8f24854bcddfd..de75ef6158216 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -607,14 +607,6 @@ pub trait IteratorExt: Iterator + Sized { /// Performs a fold operation over the entire iterator, returning the /// eventual state at the end of the iteration. /// - /// # Arguments - /// - /// * `init` - initial value for accumulator, it is also returned if iterator is empty - /// * `func(acc, item)` - function applied to the elements - /// + `acc` - accumulator = value returned by last call of `func` (or `init` if it is first - /// call) - /// + `item` - current element - /// /// # Examples /// /// ``` @@ -623,12 +615,12 @@ pub trait IteratorExt: Iterator + Sized { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn fold(self, init: B, mut func: F) -> B where + fn fold(self, init: B, mut f: F) -> B where F: FnMut(B, Self::Item) -> B, { let mut accum = init; for x in self { - accum = func(accum, x); + accum = f(accum, x); } accum }