[SR-3444] map, filter on RangeReplaceableCollection should return Self #46032
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
Additional Detail from JIRA
md5: 05669e9e4e1c642618be3a82e1ececb1
Issue Description:
Currently,
map
andfilter
onSequence
return anArray
, even though the implementation use only capabilities ofArray
that are available onRangeReplaceableCollection
* (an emptyinit
,reserveCapacity
, andappend
).This means that
RangeReplaceableCollection
could implement a version ofmap
that returned the same type. For example, aDeque
could return anotherDeque
. 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, likeSet
would need to return arrays.*(this isn't completely true: it creates a
ContiguousArray
and then turns it into anArray
. But hopefully this optimization could be removed at some point)The text was updated successfully, but these errors were encountered: