Skip to content

Instantly share code, notes, and snippets.

@FCO
Created August 19, 2023 20:44
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 FCO/56139e86d474cb8025cce5ace31fa293 to your computer and use it in GitHub Desktop.
Save FCO/56139e86d474cb8025cce5ace31fa293 to your computer and use it in GitHub Desktop.
class Agg does Callable {
has Callable @.subs;
has Signature $.signature = Signature.new: :params[|@!subs.map: |*.signature.params], :returns(Parameter.new(:type(Map())));
method CALL-ME(|c) {
%(
|@.subs.map: {
my @names = .signature.params.grep({ .named }).map(|*.named_names);
my %params := (c.hash{@names}:p).Map;
|.(|%params)
}
)
}
}
class C {
::?CLASS.^add_method: "run-at", Agg.new: :subs[ sub (:$a) { :$a }, sub (:$b) { :c($b) } ]
}
say C.run-at: :1a, :2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment