Fix small typo in filter_map() example, get rid of into_iter() for range.

Range already implements Iterator trait, so no need for the into_iter().
pull/35/head
Arcadie 4 years ago
parent fafdb36cec
commit 3263dce437

@ -4972,7 +4972,7 @@ This prints `["June", "July"]`.
`.filter_map()`. This is called `filter_map()` because it does `.filter()` and `.map()`. The closure must return an `Option<T>`, and then `filter.map()` takes the value out of each `Option` if it is `Some`. So for example if you were to `.filter_map()` a `vec![Some(9), None, Some(3)]`, it would return `[2, 3]`.
`.filter_map()`. This is called `filter_map()` because it does `.filter()` and `.map()`. The closure must return an `Option<T>`, and then `filter.map()` takes the value out of each `Option` if it is `Some`. So for example if you were to `.filter_map()` a `vec![Some(2), None, Some(3)]`, it would return `[2, 3]`.
We will write an example with a `Company` struct. Each company has a `name` so that field is `String`, but the CEO might have recently quit. So the `ceo` field is `Some<String>`. We will `.filter_map()` over some companies to just keep the CEO names.
@ -5256,7 +5256,7 @@ Some(5)
Some(6)
```
We were right: there is oone `Some(5)` and then the 1000 `Some(6)` start. So we can write this:
We were right: there is one `Some(5)` and then the 1000 `Some(6)` start. So we can write this:
```rust
fn main() {
@ -5343,8 +5343,8 @@ Something similar can be done with a range that doesn't have an ending. If you w
```rust
fn main() {
let ten_chars = ('a'..).into_iter().take(10).collect::<Vec<char>>();
let skip_then_ten_chars = ('a'..).into_iter().skip(1300).take(10).collect::<Vec<char>>();
let ten_chars = ('a'..).take(10).collect::<Vec<char>>();
let skip_then_ten_chars = ('a'..).skip(1300).take(10).collect::<Vec<char>>();
println!("{:?}", ten_chars);
println!("{:?}", skip_then_ten_chars);

Loading…
Cancel
Save