zio-interop-cats


License

License

GroupId

GroupId

dev.zio
ArtifactId

ArtifactId

zio-interop-cats_2.11
Last Version

Last Version

2.0.0.0-RC13
Release Date

Release Date

Type

Type

jar
Description

Description

zio-interop-cats
zio-interop-cats
Project URL

Project URL

https://zio.dev
Project Organization

Project Organization

dev.zio
Source Code Management

Source Code Management

https://github.com/zio/interop-cats/

Download zio-interop-cats_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/dev.zio/zio-interop-cats_2.11/ -->
<dependency>
    <groupId>dev.zio</groupId>
    <artifactId>zio-interop-cats_2.11</artifactId>
    <version>2.0.0.0-RC13</version>
</dependency>
// https://jarcasting.com/artifacts/dev.zio/zio-interop-cats_2.11/
implementation 'dev.zio:zio-interop-cats_2.11:2.0.0.0-RC13'
// https://jarcasting.com/artifacts/dev.zio/zio-interop-cats_2.11/
implementation ("dev.zio:zio-interop-cats_2.11:2.0.0.0-RC13")
'dev.zio:zio-interop-cats_2.11:jar:2.0.0.0-RC13'
<dependency org="dev.zio" name="zio-interop-cats_2.11" rev="2.0.0.0-RC13">
  <artifact name="zio-interop-cats_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='dev.zio', module='zio-interop-cats_2.11', version='2.0.0.0-RC13')
)
libraryDependencies += "dev.zio" % "zio-interop-cats_2.11" % "2.0.0.0-RC13"
[dev.zio/zio-interop-cats_2.11 "2.0.0.0-RC13"]

Dependencies

compile (6)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
dev.zio : zio_2.11 jar 1.0.0-RC18-2
dev.zio : zio-streams_2.11 Optional jar 1.0.0-RC18-2
dev.zio : zio-test_2.11 Optional jar 1.0.0-RC18-2
org.typelevel : cats-effect_2.11 Optional jar 2.0.0
org.typelevel : cats-mtl-core_2.11 Optional jar 0.7.0

provided (1)

Group / Artifact Type Version
com.github.ghik : silencer-lib_2.11 jar 1.4.2

test (10)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.11 jar 1.14.3
co.fs2 : fs2-core_2.11 jar 2.1.0
dev.zio : zio-test-sbt_2.11 jar 1.0.0-RC18-2
org.specs2 : specs2-core_2.11 jar 4.8.3
org.specs2 : specs2-scalacheck_2.11 jar 4.8.3
org.specs2 : specs2-matcher-extra_2.11 jar 4.8.3
org.typelevel : cats-testkit_2.11 jar 2.0.0
org.typelevel : cats-effect-laws_2.11 jar 2.0.0
org.typelevel : cats-mtl-laws_2.11 jar 0.7.0
org.typelevel : discipline-scalatest_2.11 jar 1.0.0-RC1

Project Modules

There are no modules declared in this project.

Interop Cats Effect

CircleCI Releases Snapshots

This library provides instances required by Cats Effect.

ZIO Cats Effect 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].

ConcurrentEffect

In order to get a ConcurrentEffect[Task] or ConcurrentEffect[RIO[R, *]] we need an implicit Runtime[R] in scope. The easiest way to get it is using ZIO.runtime:

import cats.effect._
import zio._
import zio.interop.catz._

def getCE = {
  ZIO.runtime.map { implicit r: Runtime[Any] =>
    val F: ConcurrentEffect[Task] = implicitly
  }
}

Task.concurrentEffectWith method can automate this pattern:

import cats.effect._
import zio._
import zio.interop.catz._

def fork = {
  Task.concurrentEffectWith { implicit CE =>
    CE.start(Task(println("Started 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.

cats-core

If you only need instances for cats-core typeclasses, not cats-effect import zio.interop.catz.core._:

import zio.interop.catz.core._

Note that this library only has an Optional dependency on cats-effect – if you or your libraries don't depend on it, this library will not add it to the classpath.

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)
dev.zio

ZIO

ZIO — Real World Functional Programming

Versions

Version
2.0.0.0-RC13
2.0.0.0-RC12
2.0.0.0-RC11
2.0.0.0-RC10
2.0.0.0-RC9
2.0.0.0-RC8
2.0.0.0-RC7
2.0.0.0-RC6
2.0.0.0-RC5
2.0.0.0-RC4
2.0.0.0-RC3
2.0.0.0-RC2
2.0.0.0-RC1
1.3.1.0-RC3
1.3.1.0-RC2
1.0.0-RC8-12
1.0.0-RC8-11
1.0.0-RC8-10
1.0.0-RC8-9
1.0.0-RC8-8
1.0.0-RC8-7
1.0.0-RC8-6
1.0.0-RC8-5
1.0.0-RC8-4
1.0.0-RC8
1.0.0-RC6