Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Improve foreach with help of map?

by Porculus (Hermit)
on Oct 13, 2009 at 22:33 UTC ( [id://800987]=note: print w/replies, xml ) Need Help??


in reply to Re: Improve foreach with help of map?
in thread Improve foreach with help of map?

You're overthinking this. No need to worry about functional programming, purity, parallelisation, or any of that. The "map" concept in purely-functional programming languages is very interesting in its own right, but it has no more in common with Perl's map than mathematical functions have with Perl functions.

Perl's map is the wrong tool for the job purely because it does not do the job very well. It is good at iterating over a complete array and returning a new array, while the job was, IIUC, to iterate over part of an array and return a scalar.

If Perl's map did happen to do the job very well, then how could it be the wrong tool for it? For example, the pure FP map function must always produce exactly the same number of elements as it consumes. Perl's map can produce as many output elements as it likes for each input element, or it can skip it completely and produce nothing. In cases where that's desirable, it's perfectly appropriate to do it, without feeling guilty because a pure FP language would require an additional filtering step after the mapping was complete!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://800987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2024-04-18 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found