Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add collecting methods to aggregating classes #10429

Open
vbradnitski opened this issue Feb 29, 2024 · 0 comments
Open

add collecting methods to aggregating classes #10429

vbradnitski opened this issue Feb 29, 2024 · 0 comments
Assignees

Comments

@vbradnitski
Copy link
Contributor

vbradnitski commented Feb 29, 2024

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 vbradnitski self-assigned this Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants