Created
February 15, 2015 06:10
-
-
Save raydiak/1ecf3131e1fa4157e625 to your computer and use it in GitHub Desktop.
Whatever support for positional currying
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
#!/usr/bin/env perl6 | |
sub assuming ($r, |curried) { | |
if my @holes := (^curried).grep: { curried[$_] ~~ Whatever } { | |
my $last-hole = @holes[*-1]; | |
my @mixed; | |
@mixed[$_] := curried[$_] for 0 .. $last-hole; | |
my @curried := curried[$last-hole ^.. *]; | |
return sub CURRIED (|direct) { | |
@mixed[@holes[$_]] := direct[$_] for ^@holes; | |
$r(|@mixed, |@curried, |@(direct[+@holes .. *]), |%(curried), |%(direct)); | |
} | |
} | |
return sub CURRIED (|direct) { | |
$r(|curried, |direct) | |
} | |
} | |
assuming(&say, *, 2, *, 4)(1, 3); | |
assuming(&foo, 1..3, *, [7,8,9])( (4,5,6) ); | |
assuming(assuming(&say, *, *, 3), *, 2)(1); | |
sub foo { | |
.perl.say for $^a, $^b, $^c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment