Collectors inventory (original) (raw)
Brian Goetz brian.goetz at oracle.com
Thu Feb 21 15:01:30 PST 2013
- Previous message: Code review request
- Next message: Collectors inventory
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
As I promised a long time ago, here's an overview of what's in Collectors currently.
There are 12 basic forms:
toCollection(ctor)
toList()
toSet()
toStringBuilder()
toStringJoiner(delimiter)
to{Long,Double}Statistics
groupingBy(classifier, mapFactory, downstream collector)
groupingReduce(classifier, mapFactory, mapper, reducer)
mapping(mappingFn, downstream collector)
joiningWith(mappingFunction, mergeFunction, mapFactory)
partitioningBy(predicate, downstream collector)
partitioningReduce(predicate, mapper, reducer)
The toXxx forms should be obvious.
Mapping has four versions, analogous to Stream.map:
- mapping(T -> U, Collector<U, R>)
- mapping(T -> int, Collector.OfInt)
- mapping(T -> long, Collector.OfLong)
- mapping(T -> double, Collector.OfDouble)
GroupingBy has four forms:
- groupingBy(T->K) -- standard groupBy, values of resulting Map are Collection
- Same, but with explicit constructors for map and for rows (so you can produce, say, a TreeMap<K, TreeSet> and not just a Map<K,Collection>)
- groupingBy(T->K, Collector<T,D>) -- multi-level groupBy, where downstream is another Collector
- Same, but with explicit ctor for map
GroupingReduce has four forms:
- groupingReduce(T->K, BinaryOperator) // simple reduce
- groupingReduce(T->K, Function<T,U>, BinaryOperator) // map-reduce
- above two with explicit map ctors
JoiningWith has four forms:
- joiningWith(T->U)
- same, but with explicit Map ctor
- same, but with merge function for handling duplicates
- same, with both explicit map ctor and merge function
PartitioningBy has three forms:
- partitioningBy(Predicate)
- Same, but with explicit constructor for Collection (so you can get a Map<Boolean, TreeSet>)
- partitioningBy(Predicate, Collector) // multi-level
PartitioningReduce has two forms:
- predicate + reducer
- predicate + mapper + reducer
Impl note: in any category, all but one are one-liners that delegate to the general form.
Plus, all the Map-bearing ones have a concurrent and non-concurrent version.
- Previous message: Code review request
- Next message: Collectors inventory
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-observers mailing list