Skip to content

Commit

Permalink
If it's good enough for unshift, it's ok for push
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jun 13, 2015
1 parent af886d1 commit 6884d0b
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/core/List.pm
Expand Up @@ -256,7 +256,27 @@ my class List does Positional { # declared in BOOTSTRAP
!! fail X::Cannot::Empty.new(:action<.shift>, :what(self.^name));
}

my &list_push = multi method push(List:D: *@values) {
multi method push(List:D: \value) {
if nqp::iscont(value) || nqp::not_i(nqp::istype(value, Iterable)) && nqp::not_i(nqp::istype(value, Parcel)) {
$!nextiter.DEFINITE && self.gimme(*);
fail X::Cannot::Infinite.new(:action<.push to>)
if $!nextiter.DEFINITE;
nqp::p6listitems(self);
nqp::istype(value, self.of)
?? nqp::push($!items, nqp::assign(nqp::p6scalarfromdesc(nqp::null), value))
!! X::TypeCheck.new(
operation => '.push',
expected => self.of,
got => value,
).throw;
self
}
else {
callsame();
}
}

multi method push(List:D: *@values) {
fail X::Cannot::Infinite.new(:action<.push>, :what(self.^name))
if @values.infinite;
nqp::p6listitems(self);
Expand Down Expand Up @@ -284,26 +304,6 @@ my class List does Positional { # declared in BOOTSTRAP
self;
}

multi method push(List:D: \value) {
if nqp::iscont(value) || nqp::not_i(nqp::istype(value, Iterable)) && nqp::not_i(nqp::istype(value, Parcel)) {
$!nextiter.DEFINITE && self.gimme(*);
fail X::Cannot::Infinite.new(:action<.push to>)
if $!nextiter.DEFINITE;
nqp::p6listitems(self);
nqp::istype(value, self.of)
?? nqp::push($!items, nqp::assign(nqp::p6scalarfromdesc(nqp::null), value))
!! X::TypeCheck.new(
operation => '.push',
expected => self.of,
got => value,
).throw;
self
}
else {
list_push(self, value)
}
}

multi method unshift(List:D: \value) {
if nqp::iscont(value) || !(nqp::istype(value, Iterable) || nqp::istype(value, Parcel)) {
nqp::p6listitems(self);
Expand Down

0 comments on commit 6884d0b

Please sign in to comment.