5

ZIO is not dependent on Cats, so it has its own methods to perform sequence operations: ZIO.sequencePar and ZIO.sequence.

I tried to use sequence provided by interop with Cats and it works the same way as ZIO.sequence:

import zio._
import zio.interop.catz._
import cats.implicits._ 

val t1: Task[Int] =  ???
val t2: Task[Int] =  ???
val t3: Task[Int] =  ???

val seq = List(t1,t2,t3).sequence // <-- t1,t2,t3 are executed sequentially 

(new DefaultRuntime {}).unsafeRun(seq)

Can I make ZIO treat sequence as ZIO.sequencePar, so I could run tasks in parallel?

It seems that ZIO needs some implementation of parallel Traverse for Cats, but I can't find any.

Here are my dependencies:

libraryDependencies += "dev.zio" %% "zio" % "1.0.0-RC10-1"
libraryDependencies += "dev.zio" %% "zio-interop-cats" % "2.0.0.0-RC1"

Edit:

With help of @AndreyTyukin I found that to make it works in parallel I need to run List(k,k2,k3).parSequence which use instance of typeclass Parallel available in zio-interop-cats lib. And @LuisMiguelMejíaSuárez 's comments for this question give some explanation of why we have to use Parallel.

Bogdan Vakulenko
  • 3,380
  • 1
  • 10
  • 25

0 Answers0