Skip to content
Browse files

Implement unshift

  • Loading branch information...
1 parent b727910 commit ee1fe6bb72730a4de8a73af881c942e015b1dab5 @tadzik tadzik committed Aug 1, 2011
Showing with 12 additions and 2 deletions.
  1. +10 −0 src/core/List.pm
  2. +2 −2 t/spectest.data
View
10 src/core/List.pm
@@ -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
@@ -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 }
View
4 t/spectest.data
@@ -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
@@ -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

0 comments on commit ee1fe6b

Please sign in to comment.
Something went wrong with that request. Please try again.