Home > database >  How to convert a Cats Effect Resource to ZIO 2 Scopes?
How to convert a Cats Effect Resource to ZIO 2 Scopes?

Time:08-10

I am trying to use the Cats Mongo implementation (https://github.com/Kirill5k/mongo4cats) in ZIO 2. There is a chapter in ZIO 2's doc (https://zio.dev/guides/interop/with-cats-effect#converting-resource-to-zmanaged-1) how one can convert a Cats resource to ZManaged.

But in ZIO 2 using scopes instead of ZManaged is the way to go. How do I implement that conversion?

This is the cats resource:

def catsEmbeddedMongo[F[_]: cats.effect.Async]: Resource[F, MongoClient[F]] = MongoClient.fromConnectionString[F]("mongodb://localhost:27017")

CodePudding user response:

You can call toScopedZIO with:

catsEmbeddedMongo[Task].toScopedZIO
  • Related