title: Java grouping in stream
body: <p>Java 8 streams allow us to collect elements while grouping by an arbitrary constraint. For example:</p>
  
  <pre><code>Map&lt;Type, List&lt;MyThing&gt;&gt; grouped = stream
    .collect(groupingBy(myThing -&gt; myThing.type()));
  </code></pre>
  
  <p>However this has the drawback that the stream must be completely read through, so there is no chance of lazy evaluation of future operations on <code>grouped</code>.</p>
  
  <p>Is there a way to do a grouping operation to get something like <code>Stream&lt;Tuple&lt;Type, Stream&lt;MyThing&gt;&gt;&gt;</code>? Is it even conceptually possible to group lazily in any language without evaluating the whole data set?</p>