in reply to When would you choose foreach instead of map?

In this case, there isn't a technical reason to use one over the other. In both cases, you are interested in the side-effect. So, in such case, I use map if I want to put focus on the operation, and I use foreach if I want to put focus on the data being operated on. Unless I anticipate a possible change in the code in which there will be a clear preference to use one over the other - in that case, I use that one.

Abigail

  • Comment on Re: When would you choose foreach instead of map?