I was experimenting with making the functions more perlish: wouldn’t it be nice to do
filter {$_ > 5} $list
# or
$sum = foldl {$a + $b} 0, $list
I (re)discovered that $a and $b are special globals, so we can do stuff like
$ perl -MData::Dump -Mexperimental=signatures -E '
sub myreduce :prototype(&@) ($code, $initial, @items) {
$a = $initial;
for $b (@items) {
$a = $code->();
}
return $a;
}
dd myreduce {$a + $b} 1, 2, 3, 4, 5;
'
15
Should we do this for list-ops?