]> git.lizzy.rs Git - rust.git/blob - src/docs/map_identity.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / map_identity.txt
1 ### What it does
2 Checks for instances of `map(f)` where `f` is the identity function.
3
4 ### Why is this bad?
5 It can be written more concisely without the call to `map`.
6
7 ### Example
8 ```
9 let x = [1, 2, 3];
10 let y: Vec<_> = x.iter().map(|x| x).map(|x| 2*x).collect();
11 ```
12 Use instead:
13 ```
14 let x = [1, 2, 3];
15 let y: Vec<_> = x.iter().map(|x| 2*x).collect();
16 ```