#!/usr/bin/perl
#
# eg17: currying example
#

use strict;
use warnings;
use Function::Parameters qw(:strict);

#
# my $f = curry( $func, $firstarg ):
#	Partially apply (Curry) the given function $func
#	specifying it's first argument, returning a function
#	that when given the rest of it's arguments will
#	behave as the original function.
#
fun curry( $func, $firstarg )
{
	return fun {
		return $func->( $firstarg, @_ );
	};
}

fun add($a,$b) { return $a + $b };

my $plus4 = curry( \&add, 4 );		# an "add 4 to my arg" func
my $x = $plus4->(10);			# x=10+4 i.e. 14
print "x=$x\n";
