Skip to content

Option::and_then(|v| ...(&v).then_some(v)) to Option::filter(|v| ...(v)) #12978

Open
@A4-Tacks

Description

@A4-Tacks

What it does

Improve the code to be more concise

Advantage

  • Less and cleaner

Drawbacks

No response

Example

fn foo() {
    let x = Some("foo".to_owned());

    let _y = x.and_then(|v| v.starts_with('f')
        .then_some(v));
}

Could be written as:

fn foo() {
    let x = Some("foo".to_owned());

    let _y = x.filter(|v| v.starts_with('f'));
}

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions