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-888] Sequence.minElement() and maxElement() should be protocol requirements (customization points) #43500

Open
gribozavr opened this issue Mar 6, 2016 · 5 comments
Labels
affects ABI Flag: Affects ABI feature A feature request or implementation good first issue Good for newcomers standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@gribozavr
Copy link
Contributor

Previous ID SR-888
Radar rdar://problem/24999603
Original Reporter @gribozavr
Type Bug
Status In Progress
Resolution
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, AffectsABI, StarterBug, StarterProposal, swift-evolution-proposal-needed
Assignee akhilmantha (JIRA)
Priority Medium

md5: 38f233c0b4c0d1508b74875d0c159d05

Issue Description:

Some collections naturally maintain sorted order and can implement `minElement()` and `maxElement()` in O(1). Thus, these algorithms should be protocol requirements to allow collection-specific customizations.

Note that `minElement()` and `maxElement()` that take predicates should continue to be pure extensions.

@natecook1000
Copy link
Member

How does a collection satisfy a minElement() requirement in the general case? Making the predicate version required would let the no-argument version be provided as an extension for comparable elements that simply calls the required method with <.

@gribozavr
Copy link
Contributor Author

> How does a collection satisfy a minElement() requirement in the general case?

With a default implementation that compares elements one by one.

> Making the predicate version required

That version would be a pure extension, and wouldn't allow customization, since no customization can be faster than the default.

@natecook1000
Copy link
Member

I guess I'm asking what an Array<UIImage> would return for this? Would it simply be undefined for sequences of elements that aren't Comparable, like `first` for unordered collections?

@gribozavr
Copy link
Contributor Author

Right, the no-arg method will only be defined for collections of comparable elements.

@belkadan
Copy link
Contributor

belkadan commented Mar 8, 2016

I'm not super happy with us continuing to add customization points willy-nilly. These have a definite code size cost, and we should start taking that into account or come up with an alternate implementation.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis removed bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers labels Jul 6, 2022
@AnthonyLatsis AnthonyLatsis added good first issue Good for newcomers feature A feature request or implementation and removed StarterProposal labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects ABI Flag: Affects ABI feature A feature request or implementation good first issue Good for newcomers 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

4 participants