2

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")
Chris W.
  • 2,266
  • 20
  • 40

2 Answers2

3

You can call toScopedZIO with:

catsEmbeddedMongo[Task].toScopedZIO
yangzai
  • 962
  • 5
  • 11
1

In the context of mongo4cats library, you can also use mongo4cats-zio module, which provides integration with ZIO 2. Docs: https://kirill5k.github.io/mongo4cats/docs/zio.html

herpderp
  • 11
  • 1