1

I am having trouble implementing the following function with 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] = ???

I have a branch with an attempt at implementing it, but it unfortunately does work even in the simple case (as demonstrated with a test case). The implementation of wye in scalaz-stream is not an easy read (at least for me).

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

jedesah
  • 2,983
  • 2
  • 17
  • 29
  • I am not sure if I understand what you are trying to achieve. The behaviour of wye currently uses fair, left biased policy only when awaiting the Both sides. From the description you mention, cannot you just achieve same with altering between AwaitL/R? – Pavel Chlupacek Jul 11 '15 at 19:06
  • If I wanted to alternate between AwaitL/R, wouldn't that be a deterministic merge and I could simply use a `tee.interleave` instead? I am not sure I understand "behavior of wye currently uses fair, left biased policy". How can it be both fair and left biased? I thought it was using a fair policy (of alternating between which side gets called first). What I think I want here is an unfair, left biased policy. I will provide more detail on my specific problem for context once I get access to a desktop. – jedesah Jul 12 '15 at 06:16
  • Wye is implemented the it remebers last side to read from and if, AwaitBoth is encounters, it first requests the other side, however both sides are requested at AwaitBoth, before next step is evaluated. If, left or right side completes first is obviously non.deterministics. – Pavel Chlupacek Jul 13 '15 at 06:58
  • Also please take a look on `yip` perhaps this is what you are looking for. – Pavel Chlupacek Jul 13 '15 at 06:59

0 Answers0