Skip to content

Commit

Permalink
Implement unshift
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed Aug 1, 2011
1 parent b727910 commit ee1fe6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/core/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ class List does Positional {
!! fail 'Element shifted from empty list';
}

method unshift(*@elems) {
while @elems.pop -> $e {
nqp::unshift($!items, $e)
}
self
}

method sort($by = &infix:<cmp>) {
# We defer to Parrot's ResizablePMCArray.sort method here.
# Instead of sorting elements directly, we sort a Parcel of
Expand Down Expand Up @@ -298,6 +305,9 @@ multi sub pop(@a) { @a.pop }
proto sub shift(|$) {*}
multi sub shift(@a) { @a.shift }

proto sub unshift(|$) {*}
multi sub unshift(@a, *@elems) { @a.unshift: @elems }

proto sub push(|$) {*}
multi sub push(@a, *@elems) { @a.push: @elems }

Expand Down
4 changes: 2 additions & 2 deletions t/spectest.data
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ S32-array/push.t
# S32-array/rotate.t # err: Method 'rotate' not found for invocant of class 'Array'
S32-array/shift.t
# S32-array/splice.t # err: Could not find sub &splice
# S32-array/unshift.t # err: Could not find sub &unshift
S32-array/unshift.t
# S32-basics/warn.t # err: "load_bytecode" couldn't find file 'Test/Util.pbc'
# S32-container/zip.t # err: Cannot assign to a non-container
S32-hash/exists.t
Expand All @@ -502,7 +502,7 @@ S32-io/file-tests.t
# S32-io/IO-Socket-INET.t # err: Useless declaration of a has-scoped method in mainline
S32-list/classify.t
S32-list/create.t
# S32-list/end.t # err: Method 'unshift' not found for invocant of class 'Array'
S32-list/end.t
# S32-list/first.t # err: Could not find sub &first
S32-list/grep.t
S32-list/join.t
Expand Down

0 comments on commit ee1fe6b

Please sign in to comment.