Update docs for map_flatten on Option

This commit is contained in:
dswij 2022-01-25 16:18:32 +08:00
parent ea4db3a6c6
commit 515ed80b9d

View File

@ -566,17 +566,20 @@ declare_clippy_lint! {
/// ///
/// ### Why is this bad? /// ### Why is this bad?
/// Readability, this can be written more concisely as /// Readability, this can be written more concisely as
/// `_.flat_map(_)` /// `_.flat_map(_)` for `Iterator` or `_.and_then(_)` for `Option`
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let vec = vec![vec![1]]; /// let vec = vec![vec![1]];
/// let opt = Some(5);
/// ///
/// // Bad /// // Bad
/// vec.iter().map(|x| x.iter()).flatten(); /// vec.iter().map(|x| x.iter()).flatten();
/// opt.map(|x| Some(x * 2)).flatten();
/// ///
/// // Good /// // Good
/// vec.iter().flat_map(|x| x.iter()); /// vec.iter().flat_map(|x| x.iter());
/// opt.and_then(|x| Some(x * 2));
/// ``` /// ```
#[clippy::version = "1.31.0"] #[clippy::version = "1.31.0"]
pub MAP_FLATTEN, pub MAP_FLATTEN,