Skip to content

Instantly share code, notes, and snippets.

@raydiak
Created February 15, 2015 06:10
Show Gist options
  • Save raydiak/1ecf3131e1fa4157e625 to your computer and use it in GitHub Desktop.
Save raydiak/1ecf3131e1fa4157e625 to your computer and use it in GitHub Desktop.
Whatever support for positional currying
#!/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