title: JavaScript map & find at the same time: findMap?
body: <p>How would you rewrite this without using a for loop?</p>
  
  <pre><code>const a = [2, 5, 78, 4];
  const expensiveFunction = n =&gt; 2 * n;
  
  let result;
  
  // Find the first number 
  for (let i = 0; i &lt; a.length; i++) {
      const r = expensiveFunction(a[i]);
  
      if (r &gt; 100) {
          result = r;
          break;
      }
  }
  
  console.log(result);
  </code></pre>
  
  <p>My naive approach:</p>
  
  <pre><code>const result = a.map(expensiveFunction).find(x =&gt; x &gt; 100);
  console.log(result);
  </code></pre>
  
  <p>But this runs <code>expensiveFunction</code> on all the elements, which I would like to avoid. In the above case, we should avoid running <code>expensiveFunction(4)</code>.</p>
  
  <p>Some languages have <code>find_map</code> (e.g, <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.find_map" rel="noreferrer">Rust</a>), I didn't find it in lodash nor in underscore.</p>