Posts

Showing posts with the label java-stream

Best choice: For- loop vs Streams with small list/set

Image
Clash Royale CLAN TAG #URR8PPP Best choice: For- loop vs Streams with small list/set If I have small list/set, is it better use of the for loop or streams in order to: for By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Split Java stream into two lazy streams without terminal operation

Image
Clash Royale CLAN TAG #URR8PPP Split Java stream into two lazy streams without terminal operation I understand, that in general Java streams do not split. However, we have an involved and lengthy pipeline, at the end of which we have two different types of processing that share the first part of the pipeline. Due to the size of the data, storing the intermediate stream product is not a viable solution. Neither is running the pipeline twice. Basically, what we are looking for is a solution that is an operation on a stream that yields two (or more) streams that are lazily filled and able to be consumed in parallel. By that, I mean that if stream A is split into streams B and C, when streams B and C consume 10 elements, stream A consumes and provides those 10 elements, but if stream B then tries to consume more elements, it blocks until stream C also consumes them. Is there any pre-made solution for this problem or any library we can look at? If not, where would we start to look if we wan...