Skip to content
ZIO instances for cats-effect type classes
Scala
Branch: master
Clone or download

README.md

Interop Cats Effect

CircleCI

This library provides instances required by Cats Effect.

IO Cats Effect's instances

ZIO integrates with Typelevel libraries by providing an instance of ConcurrentEffect for IO as required, for instance, by fs2, doobie and http4s. Actually, I lied a little bit, it is not possible to implement ConcurrentEffect for any error type since ConcurrentEffect extends MonadError of Throwable.

For convenience we have defined an alias as follow:

  type Task[A] = IO[Throwable, A]

Therefore, we provide an instance of ConcurrentEffect[Task].

Timer

In order to get a cats.effect.Timer[Task] instance we need an extra import:

import zio.interop.catz.implicits._

The reason it is not provided by the default "interop" import is that it makes testing programs that require timing capabilities hard so an extra import wherever needed makes reasoning about it much easier.

Example

The following example shows how to use ZIO with Doobie (a library for JDBC access) and FS2 (a streaming library), which both rely on Cats Effect instances:

import doobie.imports._
import fs2.Stream
import zio.Task
import zio.interop.catz._

val xa: Transactor[Task] = Transactor.fromDriverManager[Task](...)

def loadUsers: Stream[Task, User] =
  sql"""SELECT * FROM users""".query[User].stream.transact(xa)

val allUsers: List[User] = unsafeRun(loadUsers.compile.toList)
You can’t perform that action at this time.