The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

FP::uncurry

SYNOPSIS

    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

DESCRIPTION

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.

TODO

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.

SEE ALSO

There are various modules for currying (the inverse of uncurry) on CPAN.

`the_method` and `cut_method` in FP::Ops.

NOTE

This is alpha software! Read the status section in the package README or on the website.