1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!perl -w
use strict;
use Data::Util qw(curry);
use FindBin qw($Bin);
use lib $Bin;
use Common;
use Benchmark qw(:all);
signeture
'Data::Util' => \&curry,
;
sub f{ @_ }
print "Creation:\n";
cmpthese -1 => {
curry => sub{
my($a, $b) = (1, 3);
my $c = curry(\&f, $a, \0, $b, \1);
},
closure => sub{
my($a, $b) = (1, 3);
my $c = sub{ f($a, $_[0], $b, $_[1]) };
},
};
my($a, $b) = (1, 3);
my $c = curry(\&f, $a, \0, $b, \1);
my $d = sub{ f($a, $_[0], $b, $_[1]) };
print "Calling with subscriptive placeholders:\n";
cmpthese -1 => {
curry => sub{
$c->(2, 4) == 4 or die;
},
closure => sub{
$d->(2, 4) == 4 or die;
},
};
$c = curry(\&f, $a, *_, $b);
$d = sub{ f($a, @_[0 .. $#_], $b) };
print "Calling with the symbolic placeholder:\n";
cmpthese -1 => {
curry => sub{
$c->(1 .. 5) == 7 or die $c->(1 .. 5);
},
closure => sub{
$d->(1 .. 5) == 7 or die $d->(1 .. 5);
},
};
|