Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Currying--useful examples?

by tsee (Curate)
on Jan 11, 2007 at 08:34 UTC ( #594078=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://594078]
help
Chatterbox?
[Petroza]: Hey there, I'm new here. I tried to post a question under ''Seekers of Perl Wisdom'' and when I tried to create it An Error appeared stating that I don't have permissions to post there. Do I need some sort of an Authorization?
[LanX]: no try again
[choroba]: Didn't you forget to add a title? Did you include links to the post?
[LanX]: choroba IIRC these errors are indicated
[1nickt]: Missing title suppresses the submit button, I think.
[1nickt]: Petroza to answer your question, no, no special permission is needed to post a question.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-10-17 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (233 votes). Check out past polls.

    Notices?