FP::uncurry
use FP::uncurry; my $mult= uncurry sub { my ($x)=@_; sub { my ($y)=@_; $x*$y }}; &$mult(2,3) # -> 6 # 'uncurry' is an alias to 'uncurry_1_1' my $mult= uncurry_1_1 sub { my ($x)=@_; sub { my ($y)=@_; $x*$y }}; &$mult(2,3) # -> 6 my $mult3= uncurry_2_1 sub { my ($x,$y)=@_; sub { my ($z)=@_; $x*$y*$z }}; &$mult3(2,3,4) # -> 24
Sometimes it's easier to write code in a curried fashion. Often users still expect to receive an uncurried ("normal") version of the function. `uncurry_1_1 $fn` returns a function that expects 2 arguments, passes the first to $fn and then the second to the function that $fn returns. Other variants behave similarly: the appendix tells how many arguments each function level expects; the added numbers determine how many arguments the resulting function expects.
Add tail-call optimization to the last call in the chain. Waiting till Sub::Call::Tail is fixed, or better, we've got a switchable variant.
There are various modules for currying (the inverse of uncurry) on CPAN.
`the_method` and `cut_method` in FP::Ops.
This is alpha software! Read the status section in the package README or on the website.
To install FunctionalPerl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FunctionalPerl
CPAN shell
perl -MCPAN -e shell install FunctionalPerl
For more information on module installation, please visit the detailed CPAN module installation guide.