Skip to content
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

Replace map_or(false, ...) with is_some_and or is_ok_and #11848

Open
ronnodas opened this issue Nov 21, 2023 · 1 comment
Open

Replace map_or(false, ...) with is_some_and or is_ok_and #11848

ronnodas opened this issue Nov 21, 2023 · 1 comment
Labels
A-lint Area: New lints

Comments

@ronnodas
Copy link

What it does

The methods Option::is_some_and and Result::is_{ok,err}_and are designed to replace the common patterns map_or(false, ...) and map_err_or(false, ...). Potentially could also replace map_or(true, ...) with !is_some_and(!...). Probably should be a pedantic lint.

#9125 is similar but for map(...).unwrap_or(false).

Advantage

Expresses the intent better and is slightly more concise.

Drawbacks

No response

Example

Some(42).map_or(false, |value| value > 0)

Could be written as:

Some(42).is_some_and(|value| value > 0)
@ronnodas ronnodas added the A-lint Area: New lints label Nov 21, 2023
@y21
Copy link
Member

y21 commented Nov 21, 2023

#11796 implements the .map_or(false, ...) case.

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

No branches or pull requests

2 participants