-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add method reverse() to List #2804
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
Comments
Removed Type-Defect label. |
Added Library-Collections label. |
I note that this is polyfilled in internationalization, which should be removed once this is available. |
This comment was originally written by @seaneagan As mentioned in issue #1305, I think this method should return a view (wrapper) on the original List, rather than copying each element into a brand new List. Also, "reverse" has a mutative connotation. I think it would be better as a getter, some options for the name are: "reversed" In the case where one does want to copy the elements into a brand new List, they could do the following: var reversedCopy = new List.from(list.reversed); |
I agree that reversed is better for something that returns either a copy or a wrapper. |
Issue #5728 has been merged into this issue. |
This comment was originally written by [email protected] It'd be great if we had a unicode-aware reverse method on String as well. |
Removed Library-Collections label. |
Just last week I wanted a mutating reverse of a subrange of a list. For example, you can exchange two adjacent blocks [start, middle) and [middle,end) like this: list.reverse(start, end); |
There is now a reversed() method on List. Should this be closed? cc @floitschG. |
Closing as fixed. If there is a need for a mutating "reverse" method, it should be filed as a separate feature request. Added Fixed label. |
This issue was originally filed by @pjako
It would be nice to have a method on Lists to reverse them...
print([1,2,3].reverse());
out:
3 2 1
The text was updated successfully, but these errors were encountered: