swiftlang/swift

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

オープン

#46,032 opened on 2016/12/17

 (3 件のコメント) (0 件のリアクション) (0 人の担当者)Swift (10,719 件のフォーク)batch import
good first issueimprovementstandard libraryswift evolution proposal needed

Repository metrics

Stars
 (69,989 個のスター)
PR merge metrics
 (平均マージ 8d 17h) (30d で 510 merged PRs)

説明

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)

コントリビューターガイド