-
-
Save zoffixznet/b227823ada32ccf867449f5749c17e18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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