How to create a circular flow?

I am trying to create a circular process using a scalaz stream by merging one data source with a filtered version coming from the same data source. Here is a simple example of what I have so far:

val s1 = Process.emitAll(1 to 10).toSource

val w = wye.merge[Int]

val s2 = w.filter(_ < 5)

val w2 = s1.wye(s2)(w)

But it does not compile, as it s2is Process[Process.Env[Int,Int]#Y,Int], but it should be Process[Task,Int].

How can I indicate that s2 is both input (c s1) and output w?

+4
source share
2 answers

. scalaz. : , , .

+2

, st2, zipping wye (w) t2. , wye - , .

, t2 - Process [Task, Duration], Process [Task, Duration], wye.merge [Duration], , :

val t1: Process[Task,Duration] = ???
val t2: Process[Task,Duration] = Process.awakeEvery(3 second)

val st2: Process[Task.Duration] = t1.filter(_ < 5 seconds).zip(t2).map(_._1)
val w2: Process[Task.Duration] = t1.wye(st2)(wye.merge) //or simply t1.merge(t2)

, anotations .

+3

All Articles