Running scalaz-stream's Process gives could not find implicit value for parameter C: scalaz.Catchable[F2]?
Asked Answered
C

2

6

Why am I getting the following error: could not find implicit value for parameter C: scalaz.Catchable[F2] when executing 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 at GitHub. Execute sbt console and then P(1,2,3).run to face the issue.

Caucus answered 7/4, 2014 at 21:33 Comment(0)
K
8

When you write Process(1, 2, 3), you get a Process[Nothing, Int], which is a process that doesn't have any idea about a specific context that it can make external requests against—it's just going to emit some stuff. This means that you can treat it as a Process0, for example:

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

It does also mean that you can't run it, though, since run needs a "driver" context.

Since Process is covariant in its first type parameter, you can use it in situations where you do 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 little confusing, but in normal usage you won't generally run into this situation, since you'll be using the process in a context that will fix its type to something like Process[Task, Int].

Kellene answered 8/4, 2014 at 9:49 Comment(0)
I
1

On a Process0[O] like Process(1, 2, 3) you can call .toSource in order to transform it to a Process[Task, O] and runLog.run it or alternatively you can call directly Functions like toList, toVector etc. to get its result.

Isomorphism answered 16/10, 2015 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.