Skip to content

Commit f198b0a

Browse files
authored
Fix confusing doc for scan
The comment "the value passed on to the next iteration" confused me since it sounded more like what Haskell's [scanl](http://hackage.haskell.org/package/base-4.11.0.0/docs/Prelude.html#v:scanl) does where the closure's return value serves as both the "yielded value" *and* the new value of the "state". I tried changing the example to make it clear that the closure's return value is decoupled from the state argument.
1 parent e5bf042 commit f198b0a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libcore/iter/iterator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,13 @@ pub trait Iterator {
974974
/// // each iteration, we'll multiply the state by the element
975975
/// *state = *state * x;
976976
///
977-
/// // the value passed on to the next iteration
978-
/// Some(*state)
977+
/// // then, we'll yield the negation of the state
978+
/// Some(-*state)
979979
/// });
980980
///
981-
/// assert_eq!(iter.next(), Some(1));
982-
/// assert_eq!(iter.next(), Some(2));
983-
/// assert_eq!(iter.next(), Some(6));
981+
/// assert_eq!(iter.next(), Some(-1));
982+
/// assert_eq!(iter.next(), Some(-2));
983+
/// assert_eq!(iter.next(), Some(-6));
984984
/// assert_eq!(iter.next(), None);
985985
/// ```
986986
#[inline]

0 commit comments

Comments
 (0)