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

[SR-8437] Add filter method to Optional #50960

Open
palimondo mannequin opened this issue Aug 1, 2018 · 1 comment
Open

[SR-8437] Add filter method to Optional #50960

palimondo mannequin opened this issue Aug 1, 2018 · 1 comment
Labels
feature A feature request or implementation standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@palimondo
Copy link
Mannequin

palimondo mannequin commented Aug 1, 2018

Previous ID SR-8437
Radar None
Original Reporter @palimondo
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels New Feature, LanguageFeatureRequest
Assignee None
Priority Medium

md5: 3852b2408d69c13546d326891036b911

Issue Description:

There is a strong precedent from other programming languages that have optional types to include method named filter that conditionally maps the optional to nil. The implementation is trivial:

extension Optional {
    func filter(_ predicate: (Wrapped) throws -> Bool) rethrows -> Optional {
        return try flatMap { try predicate($0) ? self : nil }
    }
}

Swift is currently missing this method. When pitched in Swift Evolution Forums, this method was met with no opposition. This looks like a clear omission without any downsides, that should be easy to add into Swift standard library without the need to go through lengthy Swift Evolution process.

@belkadan
Copy link
Contributor

belkadan commented Aug 1, 2018

API additions always go through the Swift Evolution process.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal and removed new feature labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

2 participants