scalaz-stream: toStream

I was writing a scalaz-stream app the other day and could not figure out what .toStream really did. I looked at the unit test (the examples and unit tests are a great way to learn the library) and figured it out.

When you create a Process0, a process that only has outputs, you need to eventually convert it to a Process[F[_], O]. Process0 means only outputs with zero inputs. Process1 means one input and one output. Here's the line that helped me:

 val source = emitAll(Seq(1,2,3)).toSource

Once I saw that it made sense. emitAll() does not have an environment F[_] defined for it. It needs one in order to be able to run. So whenever you create a Process0 or Process1, you'll need to add an environment. If you are like me, I usually use the Task environment. Using toSource converts a Process0 to the default F[_] environment of task to create a Process[Task, Int] instead of a just a Process0[Int]. That's it!


Popular posts from this blog

zio layers and framework integration

typescript and react types

dotty+scala.js+async: interesting options