title: When should I use a Map instead of a For Loop?
body: <p>This is relating to the following: (In Python Code)</p>
  
  <pre><code>for i in object:
       doSomething(i)
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>map(doSomething, object)
  </code></pre>
  
  <p>Both are easy to understand, and short, but is there any speed difference?  Now,  if doSomething had a return value we needed to check it would be returned as a list from map, and in the for loop we could either create our own list or check one at a time.</p>
  
  <pre><code>for i in object:
       returnValue = doSomething(i)
       doSomethingWithReturnValue(returnValue)
  </code></pre>
  
  <p>versus</p>
  
  <pre><code>returnValue = map(doSomething, object)
  map(doSomethingWithReturnValue, returnValue)
  </code></pre>
  
  <p>Now, I feel the two diverge a little bit.  The two doSomethingWithReturnValue functions may be different based on if checking them on the fly as we go through the loop or if checking them all at once at the end produce different results.  Also it seems the for loop would always work, maybe slower, where the map would only work under certain scenarios.  Of course, we could make contortions to make either work, but the whole point is to avoid this type of work.</p>
  
  <p>What I'm looking for is a scenario where the mapping function truly shines in comparison to a well done for loop in performance, readability, maintainability, or speed of implementation.  If the answer is there really isn't a big difference then I'd like to know when in practice people use one or the other or if it's really completely arbitrary and set by coding standards depending on your institution.</p>
  
  <p>Thanks!</p>