Imagine we have a Collector
, and we want to feed it the contents of a succession of Stream
s.
The most natural way of doing it would be concatenating the Stream
s and feeding the Collector
with the concatenation. But this might not be optimal: for example, if each Stream
reads from a scarce resource allocated with a try-with-resources, it would be expensive to have all Stream
s at once.
Also, sometimes we might not even have direct access to the Stream
s, we might only have an opaque method that "feeds" a Collector
that it receives as parameter, and returns the result.
How to feed a Collector
from multiple sources in those cases?