http://www.perlmonks.org?node_id=594078


in reply to Re: Currying--useful examples?
in thread Currying--useful examples?

It's really quite simple to write a curry-able map in Perl. I'd expect it to be pretty slow, though, because of the many subroutine calls: 2+n for a list of n elements. If "map CODE, LIST" treats CODE as a subroutine, that makes 2+2*n calls.
And $_++ won't work.

use strict; use warnings; sub cmap (&) { my $map = shift; return sub { map $map->($_), @_ }; } my $incr = cmap {$_*2}; print join " ", $incr->(2..5); print "\n"; # 4 6 8 10

Steffen