diff options
Diffstat (limited to 'src/tools/clippy/src/docs/map_flatten.txt')
-rw-r--r-- | src/tools/clippy/src/docs/map_flatten.txt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/map_flatten.txt b/src/tools/clippy/src/docs/map_flatten.txt new file mode 100644 index 000000000..73c0e5140 --- /dev/null +++ b/src/tools/clippy/src/docs/map_flatten.txt @@ -0,0 +1,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)); +```
\ No newline at end of file |