I have a situation. I have a repo which has a depe...
# arrow
g
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.
Copy code
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" }
}
r
Hi @Gopal S Akshintala, the issue here is that Monad is not capable enough to take an effect in IO and lift it to a generic Kind. To bridge that gap there is Async. Async has the powers to take any effect in any library that may complete async and turn it into a suspended function or callback you can manually complete. The code below may work for your purpose:
g
Thanks alot @raulraja 🙂
👍 1