Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make List.roll(1)/pick(1) match List.roll/pick
  • Loading branch information
lizmat committed May 9, 2015
1 parent 16ba247 commit 70ac241
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/List.pm
Expand Up @@ -225,7 +225,9 @@ my class List does Positional { # declared in BOOTSTRAP
## of the list, resulting in an O(n) algorithm.

my Int $elems = self.elems;
return () unless $elems;
unless $elems {
return number == 1 ?? Nil !! ();
}

my int $n = number > $elems ?? $elems !! number.Int;
return nqp::atpos($!items,$elems.rand.floor) if $n == 1;
Expand Down Expand Up @@ -398,7 +400,9 @@ my class List does Positional { # declared in BOOTSTRAP

fail X::Cannot::Infinite.new(:action<.roll from>) if self.infinite;
my $elems = self.elems;
return () unless $elems;
unless $elems {
return number == 1 ?? Nil !! ();
}

my int $n = number.Int;
return nqp::atpos($!items,$elems.rand.floor) if $n == 1;
Expand Down

0 comments on commit 70ac241

Please sign in to comment.