I am trying to create an example of a ZIO Module, that has two implementations:
- Using YAML with circe-yaml
- Using HOCON with pureConfig
My general Interface looks like this:
trait Service[R] {
def load[T <: Component](ref: CompRef): RIO[R, T]
}
Now my YAML implementation looks like:
def loadYaml[T <: Component: Decoder](ref: CompRef): RIO[Any, T] = {...}
The Decoder
is implementation specific.
The problem is now how to delegate from the Service implementation to loadYaml
.
I tried the following:
val components: Components.Service[Any] = new Components.Service[Any] {
implicit val decodeComponent: Decoder[Component] =
List[Decoder[Component]](
Decoder[DbConnection].widen,
...
).reduceLeft(_ or _)
def load[T <: Component](ref: CompRef): RIO[Any, T] = loadYaml[T] (ref)
}
This gives me:
Error:(62, 20) could not find implicit value for evidence parameter of type io.circe.Decoder[T]
loadYaml[T] (ref)
Is there a way to achieve this?
I created an example project on Github: zio-comps-module
The idea is described here: Decouple the Program from its Implementation with ZIO modules