RS.CLIPPY.MAP_FLATTEN
Using combinations of `flatten` and `map` which can usually be written as a single method call
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: map_flatten. Copyright ©2025 The Rust Team. All rights reserved.
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));