swiftlang/swift

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

开放

#46,032 创建于 2016年12月17日

 (3 条评论) (0 个反应) (0 位负责人)Swift (10,719 个派生)batch import
good first issueimprovementstandard libraryswift evolution proposal needed

仓库指标

星标
 (69,989 个星标)
PR 合并指标
 (平均合并 8天 17小时) (30 天内合并 510 个 PR)

描述

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)

贡献者指南