I have a pretty dumb question. We all know that a thread can have several intermediate operations, but the actual calculation is performed only when some terminal operation is called. Is it common to transmit streams without a long-term call to a terminal operation?
Let me explain what I mean. Consider the following example with Iterator / Iterable
- Read the file with a buffered reader in lines, return Iterator with next () canceled
reader.readLine() - In the upper class, use guava Iterators.transform to say lowercase letters all.
- In the transfer of the upper class with another Iterator, which can be divided by a line from the ascending iterator by coma and returning tuples of the word in the line
- In the last class, an iterator consumes an iteration over it and writes some OutputStream.
With all of this, I have complete lazy calculations done from the very beginning to the end. No intermediate collections, etc.
If I wanted to do the same with streams, then I probably needed to get around the Stream object. Is this very common? Can you share some links with me?
source
share