1

我在使用 scalaz-stream 实现以下功能时遇到问题:

/**
 * Same as `merge` but is biased on the left side. Both `merge` and `mergeLeftBias` are
 * non-deterministic, but `merge` tries to balance results from both to the extent the 
 * input streams are producing results at roughly the same speed. `mergeLeftBias` 
 * does not make any guarantees, but it will tend to grab elements from the left 
 * before the right. This is can be useful if, for instance,  working with two streams
 * that have interdependencies, i.e. the left stream produces results indirectly 
 * from the right stream being pulled from. This is a fairly common scenario that 
 * arises when using a `Queue` to merge "back" together a stream that was separated by
 * some black box API that was not build over scalaz-stream.
 */
def mergeLeftBias[I]: Wye[I,I,I] = ???

我有一个尝试实现它的分支,但不幸的是它即使在简单的情况下也可以工作(如测试用例所示)。在 scalaz-stream 中的实现wye并不容易阅读(至少对我来说)。

https://github.com/jedesah/scalaz-stream/tree/topic/mergeLeftBiased

4

0 回答 0