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

stdlib: Array.rotate rotates opposite to List.rotate #1470

Closed
spotandjake opened this issue Nov 7, 2022 · 2 comments · Fixed by #1552
Closed

stdlib: Array.rotate rotates opposite to List.rotate #1470

spotandjake opened this issue Nov 7, 2022 · 2 comments · Fixed by #1552
Assignees

Comments

@spotandjake
Copy link
Member

@alex-snezhko noticed that Array.rotate and List.rotate rotate in opposite directions with.

Array.rotate - Rotating to the right.
and
List.rotate - Rotating to the left.

While you are able to rotate the other direction by using negative indexes, The behaviour seems random from a user perspective and could cause confusion.

@alex-snezhko
Copy link
Member

Since immutable arrays (#1477) make use of left-rotation like List, should Array be modified to rotate to the left as well?

@ospencer
Copy link
Member

Yes. Left rotation for all.

Ruby's doc for it makes it feel really intuitive:

Returns a new array by rotating self so that the element at count is the first element of the new array.
If count is negative then it rotates in the opposite direction, starting from the end of self where -1 is the last element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants