Skip to content

Commit d1f854a

Browse files
committed
Rollup merge of #30373 - ChrisBuchholz:master, r=steveklabnik
The current explanation for scan() is not very clear as to how it works, especially when it compares itself to fold(). I believe these changes makes it all a bit more clear for the reader, and makes it easier to understand the example code. r? @steveklabnik
2 parents 176ee34 + 5538c6b commit d1f854a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/libcore/iter.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1113,16 +1113,22 @@ pub trait Iterator {
11131113
Take{iter: self, n: n}
11141114
}
11151115

1116-
/// An iterator similar to `fold()`, with internal state.
1117-
///
1118-
/// `scan()` accumulates a final value, similar to [`fold()`], but instead
1119-
/// of passing along an accumulator, it maintains the accumulator internally.
1116+
/// An iterator adaptor similar to [`fold()`] that holds internal state and
1117+
/// produces a new iterator.
11201118
///
11211119
/// [`fold()`]: #method.fold
11221120
///
1123-
/// On each iteraton of `scan()`, you can assign to the internal state, and
1124-
/// a mutable reference to the state is passed as the first argument to the
1125-
/// closure, allowing you to modify it on each iteration.
1121+
/// `scan()` takes two arguments: an initial value which seeds the internal
1122+
/// state, and a closure with two arguments, the first being a mutable
1123+
/// reference to the internal state and the second an iterator element.
1124+
/// The closure can assign to the internal state to share state between
1125+
/// iterations.
1126+
///
1127+
/// On iteration, the closure will be applied to each element of the
1128+
/// iterator and the return value from the closure, an [`Option`], is
1129+
/// yielded by the iterator.
1130+
///
1131+
/// [`Option`]: ../option/enum.Option.html
11261132
///
11271133
/// # Examples
11281134
///

0 commit comments

Comments
 (0)