Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

ZIO instances for cats-effect type classes

License

NotificationsYou must be signed in to change notification settings

zio/interop-cats

Repository files navigation

Installation

libraryDependencies+="dev.zio"%%"zio-interop-cats"%"<latest-version>"

ZIO Cats Effect 3 instances

ZIO integrates with Typelevel libraries by providing an instance ofConcurrent,Temporal andAsync forTaskas required, for instance, byfs2,doobie andhttp4s.

For convenience, the ZIO library defines an alias as follows:

typeTask[A]=ZIO[Any,Throwable,A]

Therefore, we provide Cats Effect instances based on this specific datatype.

Concurrent

In order to get aConcurrent[Task] orConcurrent[RIO[R, *]] (note* is kind-projector notation) we need to importzio.interop.catz._:

importcats.effect._importzio._importzio.interop.catz._defceConcurrentForTaskExample= {valF: cats.effect.Concurrent[Task]= implicitlyF.racePair(F.unit,F.unit)}

Temporal

importcats.effect._importzio._importzio.interop.catz._defceTemporal= {valF: cats.effect.Temporal[Task]= implicitlyF.sleep(1.second)*>F.unit}

Async

importcats.effect._importzio._importzio.interop.catz._defceAsync= {valF: cats.effect.Async[Task]= implicitlyF.racePair(F.unit,F.sleep(1.second)*>F.unit)}

Other typeclasses

There are many other typeclasses and useful conversions that this library provides implementations for:

  • Seezio/interop/cats.scala file to see all available typeclass implementations for the Cats Effect 3 typeclasses
  • Seezio/stream/interop/cats.scala for ZStream typeclass implementations
  • Seezio/stream/interop/FS2StreamSyntax.scala for FS2 <-> ZStream conversions

cats-core

If you only need instances forcats-core typeclasses, notcats-effect importzio.interop.catz.core._:

importzio.interop.catz.core._

Note that this library only has anOptional 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 (cats.effect.Async andcats.effect.Temporal):

importzio.{durationIntas_,*}importzio.interop.catz.*importdoobie.*importdoobie.implicits.*importscala.concurrent.duration.*objectExampleextendsZIOAppDefault:valrun= {valxa:Transactor[Task]=Transactor.fromDriverManager[Task]("org.h2.Driver","jdbc:h2:mem:test;DB_CLOSE_DELAY=-1","user","",None)sql"SELECT 42"      .query[Int]      .stream      .transact(xa)      .delayBy(1.second)      .evalTap(i=>Console.printLine(i))      .compile      .drain      .exitCode  }

Documentation

Learn more on theZIO Interop Cats homepage!

Contributing

For the general guidelines, see ZIOcontributor's guide.

Code of Conduct

See theCode of Conduct

Support

Come chat with us onBadge-Discord.

License

License


[8]ページ先頭

©2009-2025 Movatter.jp