blob: 73c0e51407f28e73e0914c7bae9ad8672f2f259b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
### What it does
Checks for usage of `_.map(_).flatten(_)` on `Iterator` and `Option`
### Why is this bad?
Readability, this can be written more concisely as
`_.flat_map(_)` for `Iterator` or `_.and_then(_)` for `Option`
### Example
```
let vec = vec![vec![1]];
let opt = Some(5);
vec.iter().map(|x| x.iter()).flatten();
opt.map(|x| Some(x * 2)).flatten();
```
Use instead:
```
vec.iter().flat_map(|x| x.iter());
opt.and_then(|x| Some(x * 2));
```
|