Permalink
Browse files

implement List.classify; all tests pass except those depending on bin…

…ding
  • Loading branch information...
1 parent 977fad6 commit 916b56d60d40d02f3e620d8857d94582b896c1ae @moritz moritz committed May 7, 2010
Showing with 12 additions and 0 deletions.
  1. +11 −0 src/core/Any-list.pm
  2. +1 −0 t/spectest.data
View
@@ -175,6 +175,16 @@ augment class Any {
self.pick(Inf, :$replace);
}
+ multi method classify($test) {
+ my %result;
+ for @.list {
+ my $k = $_ ~~ $test;
+ %result{$k} //= [];
+ %result{$k}.push: $_;
+ }
+ %result.pairs;
+ }
+
multi method reduce(Code $expression is rw) {
my $arity = $expression.?count || 2; # second half is a CHEAT
fail('Cannot reduce() using a unary or nullary function.')
@@ -247,6 +257,7 @@ augment class Any {
}
}
+proto sub classify($matcher, *@values) { @values.classify($matcher) }
proto sub join (Str $separator = '', *@values) { @values.join($separator); }
proto sub reverse(@values) { @values.reverse; }
multi sub reverse(*@v) { @v.reverse; }
View
@@ -471,6 +471,7 @@ S32-hash/push.t
S32-io/file-tests.t
S32-io/note.t
# S32-io/IO-Socket-INET.t
+S32-list/classify.t
## S32-list/create.t
S32-list/end.t
S32-list/first.t

0 comments on commit 916b56d

Please sign in to comment.