Skip to content

Instantly share code, notes, and snippets.

@tony-o
Created January 13, 2023 01:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony-o/9d4fe1e20d88033649d69ab568b7ca61 to your computer and use it in GitHub Desktop.
Save tony-o/9d4fe1e20d88033649d69ab568b7ca61 to your computer and use it in GitHub Desktop.
sub trait_mod:<is> (Sub:D $s, :$partial) {
$s.wrap(sub (*%_) {
if %_.elems == $s.signature.params.elems {
callwith |%_;
} else {
my %cache = %_;
return sub (*%_) {
$s.(|%_, |%cache);
};
};
});
};
sub x (:$name, :$title) is partial {
"{$title}. {$name}".say;
};
x(:name<tony>, :title<m>);
my $partial = x(:name<tony>);
$partial.(:title<m2>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment