Merge pull request #471 from DavidDeprost/patch-1

ch13-02-iterators.md fix
This commit is contained in:
Carol (Nichols || Goulding)
2017-02-24 12:25:10 -05:00
committed by GitHub
+6 -2
View File
@@ -234,7 +234,7 @@ For example, if for some reason we wanted to take the first five values that
an instance of `Counter` produces, pair those values with values produced by
another `Counter` instance after skipping the first value that instance
produces, multiply each pair together, keep only those results that are
divisible by three, and add all the resulting values together, we could do:
divisible by three, and add all the resulting values together, we could do so:
```rust,ignore
let sum: u32 = Counter::new().take(5)
@@ -242,9 +242,13 @@ let sum: u32 = Counter::new().take(5)
.map(|(a, b)| a * b)
.filter(|x| x % 3 == 0)
.sum();
assert_eq!(48, sum);
assert_eq!(18, sum);
```
Note that zip() produces only four pairs; the theoretical fifth pair (5, None)
is never produced because zip() returns None when either of its input iterators
return None.
All of these method calls are possible because we implemented the `Iterator`
trait by specifying how the `next` method works. Use the standard library
documentation to find more useful methods that will come in handy when you're