]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/map_flatten.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / map_flatten.txt
1 ### What it does
2 Checks for usage of `_.map(_).flatten(_)` on `Iterator` and `Option`
3
4 ### Why is this bad?
5 Readability, this can be written more concisely as
6 `_.flat_map(_)` for `Iterator` or `_.and_then(_)` for `Option`
7
8 ### Example
9 ```
10 let vec = vec![vec![1]];
11 let opt = Some(5);
12
13 vec.iter().map(|x| x.iter()).flatten();
14 opt.map(|x| Some(x * 2)).flatten();
15 ```
16
17 Use instead:
18 ```
19 vec.iter().flat_map(|x| x.iter());
20 opt.and_then(|x| Some(x * 2));
21 ```