Permalink
Browse files

values, pairs, kv

  • Loading branch information...
1 parent 1b55dd4 commit 6970e7e59b48fd2ba195af46225dc691677fdf67 @moritz moritz committed Jul 22, 2011
Showing with 18 additions and 3 deletions.
  1. +3 −0 src/core/Any.pm
  2. +3 −0 src/core/Enum.pm
  3. +9 −0 src/core/List.pm
  4. +3 −3 t/spectest.data
View
@@ -20,6 +20,9 @@ my class Any {
method reverse() { self.list.reverse }
method sort($by = &infix:<cmp>) { self.list.sort($by) }
method values() { self.list }
+ method keys() { self.list.keys }
+ method kv() { self.list.kv }
+ method pairs() { self.list.pairs }
method Array() { Array.new(self.flat) }
View
@@ -9,6 +9,9 @@ my class Enum {
method kv() { $!key, $!value }
method value() { $!value }
+ method keys() { $!key }
+ method values(){ $!value }
+
multi method Str(Enum:D:) { $.key ~ "\t" ~ $.value }
multi method perl(Enum:D:) { $.key.perl ~ ' => ' ~ $.value.perl }
}
View
@@ -240,6 +240,15 @@ class List does Positional {
method keys(List:D:) {
(0..self.end).list;
}
+ method values(List:D:) {
+ self
+ }
+ method pairs(List:D:) {
+ self.keys.map: {; $_ => self.at_pos($_) };
+ }
+ method kv(List:D:) {
+ self.keys.map: { ($_, self.at_pos($_)) };
+ }
method reduce(List:D: &with) {
fail('can only reduce with arity 2 for now')
View
@@ -472,9 +472,9 @@ S32-array/create.t
S32-array/elems.t
S32-array/end.t
S32-array/exists.t
-# S32-array/keys_values.t # err: Method 'keys' not found for invocant of class 'Array'
-# S32-array/kv.t # err: Method 'kv' not found for invocant of class 'Array'
-# S23-array/pairs.t #err: Method 'pairs' not found for invocant of class 'Array'
+S32-array/keys_values.t
+S32-array/kv.t
+S23-array/pairs.t
S32-array/pop.t
S32-array/push.t
# S32-array/rotate.t # err: Method 'rotate' not found for invocant of class 'Array'

0 comments on commit 6970e7e

Please sign in to comment.