-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add Option::retain
#70
Comments
You could do this instead values.z = values.z.take().filter(|z| *z >= values.x * values.y);
|
We discussed this in the libs meetup, and we think it'd be better to instead have impl<T> Option<T> {
pub fn take_if<F: FnOnce(&mut T) -> bool>(&mut self, predicate: F) -> Option<T>;
} Feel free to open a tracking issue for |
…imulacrum Implement `Option::take_if` Tracking issue: rust-lang#98934 ACP: rust-lang/libs-team#70 [accepted]
Implement `Option::take_if` Tracking issue: #98934 ACP: rust-lang/libs-team#70 [accepted]
Implement `Option::take_if` Tracking issue: #98934 ACP: rust-lang/libs-team#70 [accepted]
Tracking issue rust-lang/rust#98934
PR for impl rust-lang/rust#98935
Proposal
Add new
Option::retain<F>(&mut self, predicate: F)
or similar to in-place replaceself
withNone
if it wasSome(x)
before and the predicate evaluated to false on the valuex
.Problem statement
Writing
if-let
statements in-between value assignments can be hideous and disturb the reading flow when updating a bunch of values in (nested) structs.Motivation, use-cases
This feature reduces the noise in the example from above:
Solution sketches
Alternative name
Maybe
retain_if
?Links and related work
Vec::retain
Vec::retain_mut
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: