Permalink
Browse files

Port lizmat++'s classify to Niecza.

  • Loading branch information...
1 parent 19355dd commit 7bae01243b6db66862902a759a93d42c8fdcb909 @colomon colomon committed Jun 26, 2013
Showing with 27 additions and 10 deletions.
  1. +27 −10 lib/CORE.setting
View
@@ -1781,17 +1781,8 @@ my class List is Cool does Positional {
method reverse() { reverse( @(self) ); }
method end() { self.elems - 1 }
- method classify(&test) {
- my %result;
- for @(self) {
- my $k = test $_;
- %result{$k} //= [];
- %result{$k}.push: $_;
- }
- %result;
- }
-
method categorize ($test) { {}.categorize( $test, self.list ) }
+ method classify ($test) { {}.classify( $test, self.list ) }
method min($cmp_ = &infix:<cmp>) {
my $cmp = $cmp_;
@@ -1996,6 +1987,32 @@ my class Hash does Associative {
self;
}
+ # proto method classify(|) { * }
+ multi method classify( &test, *@list ) {
+ for @list {
+ my $k = test($_);
+ self{$k} //= [];
+ self{$k}.push: $_;
+ }
+ self;
+ }
+ multi method classify( %test, *@list ) {
+ for @list {
+ my $k = %test{$_};
+ self{$k} //= [];
+ self{$k}.push: $_;
+ }
+ self;
+ }
+ multi method classify( @test, *@list ) {
+ for @list {
+ my $k = @test[$_];
+ self{$k} //= [];
+ self{$k}.push: $_;
+ }
+ self;
+ }
+
# proto method categorize(|) { * }
multi method categorize( &test, *@list ) {
for @list {

0 comments on commit 7bae012

Please sign in to comment.