title: reduce function composed of map function in JavaScript
body: <p>Say we have</p>
  <pre><code>var i = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  </code></pre>
  <p>and want to <code>reduce()</code> it like</p>
  <pre><code>var plus = function(a, b)
  {
    return a + b;
  };
  
  var s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    .reduce(plus);
  
  console.log(s);
  </code></pre>
  <p>Now, I want to compose <code>reduce()</code> function itself from <code>map()</code> function.</p>
  <p>How would you do that? What is the smartest way?</p>
  <p>Edit:</p>
  <p>In the comments and answers, many have claimed <code>fold</code>/<code>reduce</code> can compose map, in shallow level, that can be true, however, in category theory, fundamentally  reduce/fold is generalized to <em>Catamorphism</em> and it's all about <em>functors</em> (<code>map</code>), and it's called <em>F-algebra</em>.</p>
  <p><a href="https://en.wikipedia.org/wiki/Catamorphism" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Catamorphism</a></p>
  <p><a href="https://en.wikipedia.org/wiki/F-algebra" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/F-algebra</a></p>