In List§
See primary documentation in context for routine rotate
multi rotate(@list, Int:D $n = 1 --> Seq:D) multi method rotate(List:D: Int:D $n = 1 --> Seq:D)
Returns a Seq
with the list elements rotated to the left when $n
is positive or to the right otherwise.
Examples:
say <a b c d e>.rotate(2); # OUTPUT: (c d e a b) say <a b c d e>.rotate(-1); # OUTPUT: (e a b c d)
Note: Before Rakudo version 2020.06 a new List
was returned instead of a Seq
.
In Supply§
See primary documentation in context for method rotate
method rotate(Supply:D: $rotate = 1)
Creates a supply with elements rotated to the left when $rotate
is positive or to the right otherwise, in which case the invocant is tapped on before a new supply is returned.
my $supply = Supply.from-list(<a b c d e>).rotate(2); $supply.tap(&say); # OUTPUT: «cdeab»
Note: Available since Rakudo 2020.06.