RS.CLIPPY.FILTER_MAP_NEXT

Using combination of `filter_map` and `next` 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: filter_map_next. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for usage of _.filter_map(_).next().

Why is this bad?

Readability, this can be written more concisely as _.find_map(_).

Example

 (0..3).filter_map(|x| if x == 2 { Some(x) } else { None }).next();

Can be written as

 (0..3).find_map(|x| if x == 2 { Some(x) } else { None });

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)