Streams design strawman (original) (raw)
Brian Goetz brian.goetz at oracle.com
Sun Apr 22 09:55:09 PDT 2012
- Previous message: Streams design strawman
- Next message: Streams design strawman
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
So basically it's not a stream but something like this:
interface Histogram<K,V> { Iterable keys(); Iterable 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 "word,word,word".
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.
- Previous message: Streams design strawman
- Next message: Streams design strawman
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]