Skip to content

Implement CollectorBuilder #88

@amaembo

Description

@amaembo

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions