Skip to content

Commit

Permalink
implement List.classify; all tests pass except those depending on bin…
Browse files Browse the repository at this point in the history
…ding
  • Loading branch information
moritz committed May 7, 2010
1 parent 977fad6 commit 916b56d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/Any-list.pm
Expand Up @@ -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.')
Expand Down Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -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
Expand Down

0 comments on commit 916b56d

Please sign in to comment.