P19 - Rotate a list n places to the left.

Author: Ryan Connelly

Example

> say rotate(<a b c d e f g>.list, 3).perl;
Array.new("d", "e", "f", "g", "a", "b", "c")

Source code: P19-topo.pl

use v6;

sub rotate(@list is copy, $places is copy)
{
    $places = @list.elems + $places if $places < 0;

    for ^$places {
        @list.push: @list.shift;
    }

    @list
}

say rotate(<a b c d e f g>.list, 3).perl;
say rotate(<a b c d e f g>.list, -3).perl;