xp icon indicating copy to clipboard operation
xp copied to clipboard

add collecting methods to aggregating classes

Open vbradnitski opened this issue 11 months ago • 0 comments

Every aggregating class (Nodes, Contents, etc. ) is quite often collected from streams in an inconvenient way:

Nodes.from( collection.stream()...collect( Collectors.toList() ) );

There is a way to improve them with an util method:

 public static Collector<Node, Builder, Nodes> collecting()
    {
        return Collector.of( Builder::new, Builder::add, ( left, right ) -> left.addAll( right.build() ), Builder::build );
    }

As a result:

 collection.stream()...collect( Nodes.collecting() );

vbradnitski avatar Feb 29 '24 10:02 vbradnitski