streamly
streamly copied to clipboard
Stream combining variants
When we are combining two streams, multiple variants are possible depending on how/when we end the stream. For example, parallel has three variants:
- parallel - ends when both streams end (short for parallelBoth)
- parallelFst - ends when the first stream ends
- parallelMin - ends when any stream ends (min of the two)
The following operations can have similar variants:
- interleave (wSerial)
- merge
Note that parallelFst and parallelMin can be implemented in terms of parallel. For example:
parallelFst s1 s2 = Stream.catMaybes $ Stream.takeWhile isJust $ (Stream.map Just s1 `Stream.append` return Nothing) `parallel` Stream.map Just s2
We need to do two investigations:
- Write benchmarks and check if the idiomatic implementation above have the same perf as the custom implementation? If they are the same then we can get rid of the custom implementations of these variants and use idiomatic ones.
- Is the naming correct/intuitive keeping all possible use cases in mind or a better naming is possible?
For naming an alternative is to use parallelLeft instead of parallelFst and parallelAny instead of parallelMin.