[SR-3396] `reversed` for sequences and forward collections and should return a `ReversedRandomAccessCollection<[Iterator.Element]>`
#45,984 opened on 2016年12月12日
説明
| Previous ID | SR-3396 |
| Radar | rdar://problem/21098134 |
| Original Reporter | @airspeedswift |
| Type | Improvement |
Attachment: Download
| Votes | 0 |
| Component/s | Standard Library |
| Labels | Improvement, AffectsABI, StarterProposal |
| Assignee | None |
| Priority | Medium |
md5: 34c0ebf025eb58406a81d44f15afed48
Issue Description:
Currently calling reversed() on a bi-directional and random-access collections returns a ReversedCollection and ReversedRandomAccessCollection 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.