P19 - Rotate a list n places to the left.

Author: Ryan Connelly

Example

> say rotate(.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(.list, 3).perl;
say rotate(.list, -3).perl;