Methods by type

rotate

Full

Cyclically 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 #