Collectors update (original) (raw)
Brian Goetz brian.goetz at oracle.com
Tue Jan 29 15:22:02 PST 2013
- Previous message: Collectors update
- Next message: Collectors update
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
4. Rejigger Partition to return an array again, with an explicit lambda (which will likely be an array ctor ref) to make the array. Eliminated the silly Partition class. Please don't do that, it's pure evil.
The silly Partition class was also evil. We're in the "lesser of evils" business here.
public static Collector<T, Collection[]> partitioningBy(Predicate predicate, IntFunction<Collection[]> arraySupplier) {
in order to call this method users have to send a lambda that creates an array of parametrized type something which will be unsafe (the only way to get type safety is to create a class that inherits from Collection and to provide a type argument something like class Foo extends ArrayList {}) so while the code of the library is typesafe, no user code will never be typesafe.
Yes, let's have this discussion. The above is true, but is this really a problem? The array is simply a box for carrying the result back. The typical use case will be:
- call partition
- scoop out the two collections / reductions / whatever
- throw away the box
So the box is intended to be a short-lived container (essentially a workaround for the lack of tuples.) This is not the same case as Stream.toArray.
and BTW, the IntFunction will be always called with 2 as argument.
Yes. Is that bad?
- Previous message: Collectors update
- Next message: Collectors update
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-observers mailing list