Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
A4-Tacks opened this issue Jun 22, 2024 · 1 comment · May be fixed by #12981
Open

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

A4-Tacks opened this issue Jun 22, 2024 · 1 comment · May be fixed by #12981
Assignees
Labels
A-lint Area: New lints

Comments

@A4-Tacks
Copy link

A4-Tacks commented Jun 22, 2024

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'));
}
@A4-Tacks A4-Tacks added the A-lint Area: New lints label Jun 22, 2024
@lolbinarycat
Copy link

@rustbot claim

@lolbinarycat lolbinarycat linked a pull request Jun 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants