4

I'm trying to create a circular process using scalaz-stream by merging one source of data 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 doesn't compile as s2 is a Process[Process.Env[Int,Int]#Y,Int] but needs to be a Process[Task,Int].

How can I specify that s2 is both the input (with s1) and the output of w?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
synapski
  • 323
  • 2
  • 12

2 Answers2

3

I think the problem is in st2 that is defined like zipping wye (w) with t2. This does nt make a sense hence wye is just description how the processes will be merged.

I think t2 is Process[Task,Duration] so you will need on left side another Process[Task,Duration] and then you can use wye.merge[Duration] to merge them together like:

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)

Maybe type anotations on every line will guide your path.

Pavel Chlupacek
  • 864
  • 5
  • 8
  • Pavel, I added the `Duration` events to time my `Int` events (those are the one I care about). I simplified the code example and clarified the question: how can I specify that s2 is both the input and the output of `w`? – synapski Sep 08 '14 at 15:12
2

See this answer on the scalaz-mailing list Short answer is it's not possible to do exactly what you are asking, but there are often other ways of phrasing your problem.

pchiusano
  • 775
  • 5
  • 12