Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make List.rotate not die on empty lists
And just return itself if there's nothing to do
  • Loading branch information
lizmat committed Oct 21, 2014
1 parent 4699b5a commit 5054419
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/List.pm
Expand Up @@ -352,8 +352,13 @@ my class List does Positional { # declared in BOOTSTRAP
method rotate(Int $n is copy = 1) {
self.gimme(*);
fail 'Cannot .rotate an infinite list' if $!nextiter.defined;
my $items = nqp::p6box_i(nqp::elems($!items));
return self if !$items;

$n %= $items;
return self if $n == 0;

my Mu $res := nqp::clone($!items);
$n %= nqp::p6box_i(nqp::elems($!items));
if $n > 0 {
nqp::push($res, nqp::shift($res)) while $n--;
}
Expand Down

0 comments on commit 5054419

Please sign in to comment.