[SR-3396] reversed
for sequences and forward collections and should return a ReversedRandomAccessCollection<[Iterator.Element]>
#45984
Labels
affects ABI
Flag: Affects ABI
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
Attachment: Download
Additional Detail from JIRA
md5: 34c0ebf025eb58406a81d44f15afed48
Issue Description:
Currently calling
reversed()
on a bi-directional and random-access collections returns aReversedCollection
andReversedRandomAccessCollection
respectively. This is because the view can be placed over the underlying collection at no cost – it's just a question of transforming the index appropriately and then accessing the underlying base collection.For sequences and forward-only collections, however, this can't be done. So for these, the contents are read into an array and then that array is in-place reversed. But the second step is unnecessary – the array, once created, could just be returned wrapped in a
ReversedRandomAccessCollection
. As well as efficiency, this would have the benefit of making these methods more consistent across the board in what they return.The text was updated successfully, but these errors were encountered: