title: Functional opposite of flatmap?
body: <p>You know how flatmap takes a sequence of items and converts each one into a new subsequence, aggregating all the subsequences:</p>
  
  <pre><code>[A, B, C] -&gt; [A1, A2, B1, B2, B3, C1]
  </code></pre>
  
  <p>Is there a name for the transform which does the opposite? Something like:</p>
  
  <pre><code>[A1, A2, B1, B2, B3, C1] -&gt; [A, B, C]
  </code></pre>
  
  <p>The specific example that got me thinking about this was doing evaluation of mathematical expressions:</p>
  
  <pre><code>   1 * 2 + 3 * 4 + 5 + 6 * 7 * 8 
  -&gt; 2 + 12 + 5 + 6 + 336 
  -&gt; 361
  </code></pre>
  
  <p>Individually, the evaluation of the <code>6 * 7 * 8</code> seems like a classic <code>reduce</code> step, while deciding which blocks need to be reduced would need repeated <code>takeWhile</code> steps. </p>
  
  <p>I know how to do this in the classic iterative way, keeping track of indices and all that. For most cases, I've found a nice functional replacement for most iterative patterns. Is there a name for a single operation that does this, or a simple set of operations which can be composed to create this effect?</p>