Methods by type
rotate
FullCyclically shift a list's elements left or right.
.rotate(n) moves each element n places, wrapping around the ends — a cyclic shift. Positive n rotates left (toward the front), negative n rotates right.
Rotate left and right #
say <a b c d>.rotate(1); say <a b c d>.rotate(-1);
Output
(b c d a)
(d a b c)rotate(1) moves the first element to the back; rotate(-1) moves the last to the front.
Notes #
- Nothing is lost —
rotateis a permutation, so the result always has the same elements, just cyclically shifted. - The count wraps:
rotate(n)on a list of lengthLis the same asrotate(n % L). - Related reshapers:
rotor(chunks/windows) andreverse(flip);rotatealone shifts without reordering within the cycle.