swiftlang/swift

[SR-3444] map, filter on RangeReplaceableCollection should return Self

Open

#46.032 aperta il 17 dic 2016

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)Swift (10.719 fork)batch import
good first issueimprovementstandard libraryswift evolution proposal needed

Metriche repository

Star
 (69.989 star)
Metriche merge PR
 (Merge medio 8g 17h) (510 PR mergiate in 30 g)

Descrizione

Previous ID SR-3444
Radar None
Original Reporter @airspeedswift
Type Improvement
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)

Guida contributor