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

Suggestion: Option::take_if() #64789

Open
Boscop opened this issue Sep 25, 2019 · 0 comments
Open

Suggestion: Option::take_if() #64789

Boscop opened this issue Sep 25, 2019 · 0 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Boscop
Copy link

Boscop commented Sep 25, 2019

Suggestion: Adding Option::take_if().
It takes a predicate (similar to filter, but for conditional .take()):

pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
where
    P: FnOnce(&T) -> bool 
{
    match self {
        Some(x) if predicate(x) => self.take(),
        _ => None,
    }
}
@csmoe csmoe added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants