Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created March 8, 2017 18:32
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 zoffixznet/b227823ada32ccf867449f5749c17e18 to your computer and use it in GitHub Desktop.
Save zoffixznet/b227823ada32ccf867449f5749c17e18 to your computer and use it in GitHub Desktop.
use nqp;
sub infix:<zo> (&f, &g) {
my \ret = &f.count > 1
?? sub (|args) { f |g |args }
!! sub (|args) { f g |args }
nqp::bindattr(ret, Code, '$!signature',
nqp::getattr(nqp::decont(&g), Code, '$!signature'));
ret;
}
sub one ($a, $b) { $a + $b };
sub two ($x) { $x² }
my &combined = &two zo &one;
say combined 2, 4;
say combined(2, 4)³;
sub three ($x) { $x³ }
my &co-combined = &three zo &combined;
say co-combined 2, 4;
say &one.count;
say &one.arity;
say &co-combined.count;
say &co-combined.arity;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment