I have a program to read data from multiple sources, use a tournament tree to merge sort them, pack the data into blocks and output the blocks. I have implemented this as a function, which returns null when no more block is available.
DataBlock buildBlock()
Now I want to output a stream of blocks, but the only method I have found so far is Stream.generate
which generates an infinite stream. My stream is of course not infinite. What is a proper way to generate a finite stream from this function?