-
Notifications
You must be signed in to change notification settings - Fork 253
Open
Labels
Description
There's an idea for fluent CollectorBuilder which is similar to Stream API itself. Along with OptionalCollector (see #87) it makes complex nested collectors easier to read:
Map<Integer, List<String>> res = IntStreamEx.range(22).boxed().into(
c -> c.groupingBy(x -> x / 10,
c1 -> c1.flatMap(x -> StreamEx.of(x, x*2)).map(x -> "[" + x + "]").limit(5).toList()));
// group by and for each group select at most 5 elements after flatMap and map operations
Map<Boolean, List<Integer>> res3 = IntStreamEx.range(100).boxed().into(c -> c
.partitioningBy(x -> x % 2 == 0, c1 -> c1.limit(2).toList()));
// select at most two even and two odd numbers (short-circuiting collector)
Such API would be a very complex feature, thus careful evaluation is necessary. Also current attempts show that Eclipse Luna has bad times compiling such things (Eclipse Mars.2 works fine). Probably Luna compiler should be dropped in favor of this feature.