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-3444] map, filter on RangeReplaceableCollection should return Self #46032

Open
airspeedswift opened this issue Dec 17, 2016 · 3 comments
Open
Labels
good first issue Good for newcomers improvement standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@airspeedswift
Copy link
Member

Previous ID SR-3444
Radar None
Original Reporter @airspeedswift
Type Improvement
Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Improvement, StarterProposal, swift-evolution-proposal-needed
Assignee None
Priority Medium

md5: 05669e9e4e1c642618be3a82e1ececb1

Issue Description:

Currently, map and filter on Sequence return an Array, even though the implementation use only capabilities of Array that are available on RangeReplaceableCollection* (an empty init, reserveCapacity, and append).

This means that RangeReplaceableCollection could implement a version of map that returned the same type. For example, a Deque could return another Deque. This is probably what most users would expect for these types.

This would only apply to RRCs that could hold the mapped-to element type. Also note that, in the case of map, this would only apply to transformations that return the same element type – to represent a transformation to another type would require higher-kinder types. And sequences and non-RRC collections, like Set would need to return arrays.

*(this isn't completely true: it creates a ContiguousArray and then turns it into an Array. But hopefully this optimization could be removed at some point)

@Dante-Broggi
Copy link
Contributor

Is SE-0174 (the proposal that links to this report) going to be updated and implemented soon?

It is probably the simplest of the still-unimplemented accepted proposals.

@benrimmington
Copy link
Collaborator

In case anyone was thinking of implementing this proposal, its status may have changed, from Accepted to Withdrawn.

https://forums.swift.org/t/se-0232-remove-some-customization-points-from-the-standard-librarys-collection-hierarchy/17265/11

@airspeedswift
Copy link
Member Author

To clarify: this Jira proposes amending RRC to return Self. That was implemented as part of SE-0174. The part that wasn't was adding an associated type to Sequence to represent the filtered type. That's what I'm now thinking should be withdrawn.

The map part still needs HKTs.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added good first issue Good for newcomers 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
good first issue Good for newcomers improvement 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