Skip to content

Instantly share code, notes, and snippets.

@perlpilot
Created July 21, 2015 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlpilot/d1bda29d0928a4133a1e to your computer and use it in GitHub Desktop.
Save perlpilot/d1bda29d0928a4133a1e to your computer and use it in GitHub Desktop.
--- c/src/core/Any.pm
+++ w/src/core/Any.pm
@@ -256,7 +256,21 @@ my class Any { # declared in BOOTSTRAP
self.map({ next unless .match($test); $_ });
}
multi method grep(Callable:D $test) is rw {
- self.map({ next unless $test($_); $_ });
+ if ($test.count == 1) {
+ self.map({next unless $test($_); $_});
+ } else {
+ my role CheatArity[$a,$c] {
+ has $.arity = $a;
+ has $.count = $c;
+ }
+
+ my &tester = -> |c {
+ next unless $test(|c);
+ c.list
+ } but CheatArity[$test.arity, $test.count];
+
+ self.map(&tester);
+ }
}
multi method grep(Mu $test) is rw {
self.map({ next unless $_ ~~ $test; $_ });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment