streamly icon indicating copy to clipboard operation
streamly copied to clipboard

Stream combining variants

Open harendra-kumar opened this issue 4 years ago • 0 comments

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:

  1. 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.
  2. 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.

harendra-kumar avatar Aug 10 '21 14:08 harendra-kumar