Starting a scalaz stream. The process could not find an implicit value for the C parameter: scalaz.Catchable [F2]?

Why am I getting the following error: could not find implicit value for parameter C: scalaz.Catchable[F2] when doing P(1,2,3).run ?

 [scalaz-stream-sandbox]> console [info] Starting scala interpreter... [info] import scalaz.stream._ import scala.concurrent.duration._ P: scalaz.stream.Process.type = scalaz.stream.Process$@7653f01e Welcome to Scala version 2.11.0-RC3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0). Type in expressions to have them evaluated. Type :help for more information. scala> P(1,2,3).run <console>:15: error: could not find implicit value for parameter C: scalaz.Catchable[F2] P(1,2,3).run ^ 

The scalaz-stream-sandbox project is available on GitHub. Run sbt console and then P(1,2,3).run to solve this problem.

+6
source share
2 answers

When you write Process(1, 2, 3) , you get Process[Nothing, Int] , which is a process that has no idea of ​​the specific context from which it can make external requests - it is just going to emit some things. This means that you can treat it as Process0 , for example:

 scala> Process(1, 2, 3).toList res0: List[Int] = List(1, 2, 3) 

It also means that you cannot run it, because the driver context is required to run it.

Since Process is covariant in its parameter of the first type, you can use it in situations where you have a more specific type for this context:

 scala> import scalaz.concurrent.Task import scalaz.concurrent.Task scala> (Process(1, 2, 3): Process[Task, Int]).runLog.run res1: IndexedSeq[Int] = Vector(1, 2, 3) 

Or:

 scala> Process(1, 2, 3).flatMap(i => Process.fill(3)(i)).runLog.run res2: IndexedSeq[Int] = Vector(1, 1, 1, 2, 2, 2, 3, 3, 3) 

I agree that the error is a bit confusing, but with normal use, you usually do not encounter this situation, since you will use this process in a context that will set its type to something like Process[Task, Int] .

+8
source

On a Process0[O] like Process(1, 2, 3) you can call .toSource to convert it to Process[Task, O] and runLog.run , or vice versa, you can directly call functions like toList , toVector etc. to get his result.

+1
source

All Articles