[scalaz-streams] Cryptic error in REPL

51 views
Skip to first unread message

09goral

unread,
Feb 15, 2015, 7:30:16 PM2/15/15
to sca...@googlegroups.com
Hi, 

I am watching Daniel Spiewak presentation on scalaz-stream ( amazing guy, great teaching skills btw ) and trying the code out in REPL. at one stage i got something like this: 

scala> def debug[A](stream: Process[Task, A]): Process[Task, A] = 
     | stream map { a => s"debug: $a" } observe io.stdOutLines
<console>:23: error: type mismatch;
 found   : scalaz.stream.Process[[x]scalaz.concurrent.Task[x],String]
 required: scalaz.stream.Process[scalaz.concurrent.Task,A]
       stream map { a => s"debug: $a" } observe io.stdOutLines
                                        ^
I guess it's some kind of package issue? 

Thanks for help

etorreborre

unread,
Feb 17, 2015, 12:43:45 AM2/17/15
to sca...@googlegroups.com
I don't think so,

when you go `stream.map(a => s"debug: $a") you are effectively creating a `Process[Task, String]` but your debug method expects a `Process[Task, A]`.

One solution can be to "log" your process:

  Process.logged(stream)         // creates a Process[Task, A \/ A]
    .mapW(a => s"debug: $a")   // map the left side: Process[Task, String \/ A]
    .drainW(io.stdOutLines)       //  prints the left values to std out and discard them: Process[Task, A]

I haven't tried to compile the code above so I hope it works :-)

Eric.
Reply all
Reply to author
Forward
0 new messages