about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorTim Neumann <mail@timnn.me>2018-03-26 15:15:01 +0200
committerGitHub <noreply@github.com>2018-03-26 15:15:01 +0200
commit1233aa29de2d6f5e293f84b38ba2b02cfaf1fa0e (patch)
tree86e9a6450971d12a82eb18ead0b5036d6ffda0a8 /src/libcore
parentd601e74675b5e92b2050c1f4454138a69e620f54 (diff)
parentf198b0acf512458bdbe5079d12414ff94b03f7ac (diff)
downloadrust-1233aa29de2d6f5e293f84b38ba2b02cfaf1fa0e.tar.gz
rust-1233aa29de2d6f5e293f84b38ba2b02cfaf1fa0e.zip
Rollup merge of #49353 - chisophugis:patch-1, r=Mark-Simulacrum
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.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/iter/iterator.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs
index 2cfbc092293..31f77f92435 100644
--- a/src/libcore/iter/iterator.rs
+++ b/src/libcore/iter/iterator.rs
@@ -974,13 +974,13 @@ pub trait Iterator {
     ///     // each iteration, we'll multiply the state by the element
     ///     *state = *state * x;
     ///
-    ///     // the value passed on to the next iteration
-    ///     Some(*state)
+    ///     // then, we'll yield the negation of the state
+    ///     Some(-*state)
     /// });
     ///
-    /// assert_eq!(iter.next(), Some(1));
-    /// assert_eq!(iter.next(), Some(2));
-    /// assert_eq!(iter.next(), Some(6));
+    /// assert_eq!(iter.next(), Some(-1));
+    /// assert_eq!(iter.next(), Some(-2));
+    /// assert_eq!(iter.next(), Some(-6));
     /// assert_eq!(iter.next(), None);
     /// ```
     #[inline]