Streams design strawman (original) (raw)

Rémi Forax forax at univ-mlv.fr
Sun Apr 22 09:44:28 PDT 2012


On 04/22/2012 04:52 PM, Brian Goetz wrote:

Think "histograms." The idea is you are taking a stream of values and categorizing them. Say you have a collection of classes. One way to do this is by returning a map-stream:

classes.groupBy(c -> c.getSuperClass()) yields Object => AbstractList, AbstractSet, AbstractMap AbstractList => LinkedList, ArrayList etc. The "keys" of the new bi-stream are not (necessarily) elements of the original stream; they are drawn from the range of the mapping function passed to groupBy. We could synthesize this kind of group-by by composing a mapping operation (map element to synthetic key), producing a stream of pairs, and then a "collect" operation that collects elements mapped to a given synthetic key, and that collection operation could concatenate into a stream, count them up, etc.

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.

Rémi



More information about the lambda-dev mailing list