Gopal S Akshintala
02/19/2020, 3:07 AMDBClient
, 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" }
}
raulraja
02/19/2020, 8:25 AMGopal S Akshintala
02/19/2020, 12:29 PM