I have a Stream that does all processing in peek()
methods. I don't need any result from the Stream, but I need a terminal operation in order for processing to occur. Of course I can terminate the Stream with count()
(or any other operation), but that would be misleading as if I needed some result from Stream termination. What is the correct method to terminate the Stream in such case?
Here is the code for reference:
Stream<Collection<NetworkPart>> graphHolders = cutSegment.stream()
.map(this::obtainCollectionFor);
for (NetworkPart part : edgesToNetworkParts.get(originalSegment)) {
part.integrate(cutSegment);
graphHolders = graphHolders.peek(gh -> gh.add(part));
}
graphHolders.count(); // Just to terminate
part
s in a List and then dographHolders.forEach(gh -> gh.addAll(theParts))
? It seems you only have a need for this because of your use ofpeek
. – Darleenpeek()
-less code. – Swanner