From 5cf6253da15019e4d41bd8ff5189d15d32101058 Mon Sep 17 00:00:00 2001 From: Chris Buchholz Date: Mon, 14 Dec 2015 18:42:24 +0100 Subject: [PATCH 1/2] make scan() usage more explanatory --- src/libcore/iter.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index f063c6b06767b..4baeec9f754b0 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1113,16 +1113,22 @@ pub trait Iterator { Take{iter: self, n: n} } - /// An iterator similar to `fold()`, with internal state. - /// - /// `scan()` accumulates a final value, similar to [`fold()`], but instead - /// of passing along an accumulator, it maintains the accumulator internally. + /// An iterator adaptor similar to [`fold()`] but different because it holds + /// internal state and produces a new iterator. /// /// [`fold()`]: #method.fold /// - /// On each iteraton of `scan()`, you can assign to the internal state, and - /// a mutable reference to the state is passed as the first argument to the - /// closure, allowing you to modify it on each iteration. + /// `scan()` takes two arguments: an initial value which seeds the internal + /// state, and a closure with two arguments, the first being a mutable + /// reference to the internal state and the second an iterator element. + /// The closure can assign to the internal state to share state between + /// iterations. + /// + /// On iteration, the closure will be applied to each element of the + /// iterator and the return value from the closure, an [`Option`], is + /// yielded by the iterator. + /// + /// [`Option`]: ../option/enum.Option.html /// /// # Examples /// From 5538c6b19837a418e73aebda6ad18ae90d52b8d7 Mon Sep 17 00:00:00 2001 From: Christoffer Buchholz Date: Tue, 15 Dec 2015 08:49:57 +0100 Subject: [PATCH 2/2] Clearer leading sentence --- src/libcore/iter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 4baeec9f754b0..338305ac6d824 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1113,8 +1113,8 @@ pub trait Iterator { Take{iter: self, n: n} } - /// An iterator adaptor similar to [`fold()`] but different because it holds - /// internal state and produces a new iterator. + /// An iterator adaptor similar to [`fold()`] that holds internal state and + /// produces a new iterator. /// /// [`fold()`]: #method.fold ///