Conditionally merge transfers

Has anyone come across a piece of code to implement a conditional combination of enumerations? Essentially i have

val decideEnumeratee : Enumerate[A,Either[L,R] = Enumerate.map(a=>???) val leftSideEnumeratee : Enumeratee[L,B] = Enumeratee.map(l=>???) val rightEnumeratee: Enumeratee[R,B] = Enumeratee.map(r=>???) 

I want to have an implementation of the following combinator:

 def either[L,R,B](left:Enumeratee[L,B], right,Enumeratee[R,B]): Enumeratee[Either[L,R],B] = ??? 

Does anyone come across a similar enumeratee implementation?

+6
source share
1 answer

Here is the definition for either :

 def either[A, B, C](left: Enumeratee[A, C], right: Enumeratee[B, C]) (implicit ec: ExecutionContext) = new Enumeratee[Either[A, B], C] { def applyOn[IR](inner: Iteratee[C, IR]) = { val (liter, lenum) = Concurrent.joined[C] val (riter, renum) = Concurrent.joined[C] val liter2 = Enumeratee.mapConcat { x: Either[A, B] => x.left.toSeq } compose left transform liter val riter2 = Enumeratee.mapConcat { x: Either[A, B] => x.right.toSeq } compose right transform riter val fresult = lenum interleave renum apply inner Enumeratee.zip(liter2, riter2) mapM { _ => fresult } } } 
0
source

Source: https://habr.com/ru/post/946388/


All Articles