in reply to Re: When would you choose foreach instead of map?
in thread When would you choose foreach instead of map?
Sorry, but I just cannot agree, or even let this lay unchallenged. map and foreach are indeed different operations, as others have pointed out to great clarity. And the reason they are both in the language is because of their differences, not their similarities.
map is largely key to the "Schwartzian Transform". It not only produces a list as a side-effect (which foreach doesn't), it can produce very elaborate transformations of the input in the process. map is not hideous simply because someone doesn't understand it as well as foreach. Indeed, for those of us with a Lisp background, it's immediatly intuitive.