I have a situation. I have a repo which has a dependency
DBClient
,
which is not in my hands (say a lib impl) and it returns me a concrete type, like
IO<String>
. Now I wish to have a generic repo and only commit to a concrete type at the edge of my application, like
main()
here. But I get a compiler error in repo as commented below, which is expected. Is there any idiomatic workaround to achieve what I desire for? Thanks.
open class Repo<F>(
private val dbClient: DBClient,
M: Monad<F>
) : Monad<F> by M {
fun get(): Kind<F, String> = fx.monad {
dbClient.get() // vvv Compiler error. This needs to be converted to generic Higher kind
}
}
fun main() {
val repo = Repo(DBClient(), IO.async())
print(repo.get().fix().unsafeRunSync())
}
class DBClient {
fun get() = IO { "abc" }
}