Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created January 13, 2016 12:52
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 jonathanstowe/5c731a2daf1df24b1b5f to your computer and use it in GitHub Desktop.
Save jonathanstowe/5c731a2daf1df24b1b5f to your computer and use it in GitHub Desktop.
role Blobject {
}
subset Callback of Callable where { $_.signature.params && $_.signature ~~ :(Blobject --> Bool) };
my Callback @foo;
class One does Blobject {
}
class Two does Blobject {
}
sub one-sub(One $one) returns Bool {
say "One";
}
sub two-sub(Two $two) returns Bool {
say "Two";
}
@foo.push: &one-sub;
@foo.push: &two-sub;
sub run-em(Blobject $blob) {
sub run(|c) {
@foo.grep( -> $v { c ~~ $v.signature })>>.(|c);
}
run($blob);
}
say "Doing one";
run-em(One.new);
say "Doing two";
run-em(Two.new);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment