Skip to content

lint flat_map into filter_map #2241

Closed
@LunaBorowska

Description

@LunaBorowska

filter_map is a more specific version of flat_map. It would be neat if Clippy recommended using filter_map instead of flat_map when the function in flat_map returns Option.

This is an example from documentation with filter_map replaced by flat_map.

fn main() {
    let a = ["1", "2", "lol"];

    let mut iter = a.iter().flat_map(|s| s.parse().ok());

    assert_eq!(iter.next(), Some(1));
    assert_eq!(iter.next(), Some(2));
    assert_eq!(iter.next(), None);
}

it would be more readable with filter_map instead of flat_map.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-unnecessaryLint: Warn about unnecessary codeT-middleType: Probably requires verifiying typesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions