Streams design strawman

Brian Goetz brian.goetz at
Sun Apr 22 09:55:09 PDT 2012

> So basically it's not a stream but something like this:
> interface Histogram<K,V> {
> Iterable<K> keys();
> Iterable<V> values();
> Iterable<Entry<K,V>> entries();
> }
> a kind of super type of a Map.

It certainly could be, if we wanted to make it an eager 
(end-of-stream-pipeline) operation.  But it seems more flexible to make 
it a BiStream-creating operation (even though the values need to be 
internally buffered, which I think is your underlying point), because 
then you can keep going with more transformations / reductions on the 
resulting BiStream.  For example, the following produces a Map<Integer, 
String>, where the keys are word lengths and the values are strings of 

   words.groupBy(w -> w.length())
        .mapValues((length, words) -> String.join(words))
        .into(new HashMap<Integer, String>);

The group-by operation is rarely the end of what you want to do; usually 
you want to count, post-process, etc.

More information about the lambda-dev mailing list