Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Port lizmat++'s categorize to Niecza.

  • Loading branch information...
commit 19355dd1450e8a21c41dc8322637084486f75efc 1 parent 43813cf
@colomon colomon authored
Showing with 30 additions and 11 deletions.
  1. +30 −11 lib/CORE.setting
View
41 lib/CORE.setting
@@ -1791,17 +1791,7 @@ my class List is Cool does Positional {
%result;
}
- method categorize(&test) {
- my %result;
- for @(self) {
- my @k = test $_;
- for @k -> $k {
- %result{$k} //= [];
- %result{$k}.push: $_;
- }
- }
- %result;
- }
+ method categorize ($test) { {}.categorize( $test, self.list ) }
method min($cmp_ = &infix:<cmp>) {
my $cmp = $cmp_;
@@ -2006,6 +1996,35 @@ my class Hash does Associative {
self;
}
+ # proto method categorize(|) { * }
+ multi method categorize( &test, *@list ) {
+ for @list {
+ for test($_) -> $k {
+ self{$k} //= [];
+ self{$k}.push: $_;
+ }
+ }
+ self;
+ }
+ multi method categorize( %test, *@list ) {
+ for @list {
+ for %test{$_} -> $k {
+ self{$k} //= [];
+ self{$k}.push: $_;
+ }
+ }
+ self;
+ }
+ multi method categorize( @test, *@list ) {
+ for @list {
+ for @test[$_] -> $k {
+ self{$k} //= [];
+ self{$k}.push: $_;
+ }
+ }
+ self;
+ }
+
# Rakudo extensions compatibility - DO NOT USE
method delete($key) { self.{$key}:delete }
method exists($key) { self.{$key}:exists }
Please sign in to comment.
Something went wrong with that request. Please try again.