I have a question about ZLayers.
In my app i want to have possibility of connecting to different types of databases. So i want to be able to create connection pool differently.
How should i write it? Let’s say i have:
sealed trait MyAppConfig
case class Postgres(...) extends MyAppConfig
case class H2File(...) extends MyAppConfig
Then, i want to create connection pool layer:
val zioPoolConfig: ULayer[ZConnectionPoolConfig] = ZLayer.succeed(ZConnectionPoolConfig.default)
val live: Zlayer[MyAppConfig, Throwable, ZConnectionPool] = (c: MyAppConfig) => c match
case p: Postgres => zioPoolConfig >>> ZConnectionPool.postgres(......)
case h: H2File => zioPoolConfig >>> ZConnectionPool.h2File(....)
But i get an error – compiler found MyAppConfig => ZLayer[Any, Throwable, ZConnectionPool] instead of a ZLayer[MyAppConfig, Throwable, ZConnectionPool].
I tried to wrap it into ZLayer.fromFunction constructor, but i get “?1Out found instead of the correct type” error.
So, how to write it, to make it work?