Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor List.pop to be more in line code-wise with List.shift and Li…
…st.push.
  • Loading branch information
pmichaud committed Jul 1, 2011
1 parent 22676c5 commit 37489f0
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/core/List.pm
Expand Up @@ -95,6 +95,14 @@ class List does Positional {
)
}

method pop() {
my $elems = self.elems;
fail '.pop from an infinite list NYI' if $!nextiter.defined;
$elems > 0
?? nqp::pop($!items)
!! fail 'Element popped from empty list';
}

method push(*@values) {
my $pos = self.elems;
fail '.push on infinite lists NYI' if $!nextiter.defined;
Expand All @@ -116,19 +124,7 @@ class List does Positional {
# make sure we have at least one item, then shift+return it
self.gimme(1)
?? nqp::shift($!items)
!! fail 'Element shifted from empty array';
}

method pop() {
# .elems also reifies
my $e := self.elems;
$e == $Inf
?? fail('Pop from infinite array')
!! (
$e == 0
?? fail('Pop from empty array')
!! nqp::pop($!items)
);
!! fail 'Element shifted from empty list';
}

multi method perl(List:D \$self:) {
Expand Down

0 comments on commit 37489f0

Please sign in to comment.