Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7266] reversed() applied multiple times should not nest ReversedCollection into itself #49814

Closed
moiseev mannequin opened this issue Mar 23, 2018 · 3 comments
Closed
Assignees
Labels
good first issue Good for newcomers improvement standard library Area: Standard library umbrella

Comments

@moiseev
Copy link
Mannequin

moiseev mannequin commented Mar 23, 2018

Previous ID SR-7266
Radar None
Original Reporter @moiseev
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement, StarterBug
Assignee @Moximillian
Priority Medium

md5: d7a13ecbc1a535d769141383adecf60a

Issue Description:

Right now applying reversed() twice will result in a ReversedCollection<ReversedCollection<Base>>.

(swift) [1,2].lazy.reversed()
// r0 : LazyCollection<ReversedCollection<[Int]>> = Swift.LazyCollection<Swift.ReversedCollection<Swift.Array<Swift.Int>>>(_base: Swift.ReversedCollection<Swift.Array<Swift.Int>>(_base: [1, 2]))
(swift) r0.reversed()
// r1 : LazyCollection<ReversedCollection<ReversedCollection<[Int]>>> = Swift.LazyCollection<Swift.ReversedCollection<Swift.ReversedCollection<Swift.Array<Swift.Int>>>>(_base: Swift.ReversedCollection<Swift.ReversedCollection<Swift.Array<Swift.Int>>>(_base: Swift.ReversedCollection<Swift.Array<Swift.Int>>(_base: [1, 2])))
(swift) [1].reversed()
// r2 : ReversedCollection<[Int]> = Swift.ReversedCollection<Swift.Array<Swift.Int>>(_base: [1])
(swift) r2.reversed()
// r3 : ReversedCollection<ReversedCollection<[Int]>> = Swift.ReversedCollection<Swift.ReversedCollection<Swift.Array<Swift.Int>>>(_base: Swift.ReversedCollection<Swift.Array<Swift.Int>>(_base: [1]))

I believe we can be smarter and avoid this nesting.

@Moximillian
Copy link
Contributor

The regular (non-lazy) version fixed in #15815

@Moximillian
Copy link
Contributor

lazy version fixed in the PR, by adding ReversedCollectionProtocol

@moiseev
Copy link
Mannequin Author

moiseev mannequin commented Apr 12, 2018

Merged the non-lazy variant here: 02aef12

Lazy version is harder to implement without extra protocols or new compiler features, so not doing it for now.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers improvement standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant