doing an `fx` block with a single line `!` is the same as just pulling the thing you’re binding out...
p
doing an
fx
block with a single line
!
is the same as just pulling the thing you’re binding outside
g
Thanks, but I still have to repeat that
effect { libDBClient.get().k().suspended() }
in all my TCs, is there any way to abstract it out in common place, or is it inevitable?
p
make a function out of it
g
But the
libDBClient
type is not polymorphic
p
Copy code
fun <F> Observable<A>.toKind(): Kind<F, A> = effect { k().suspended() }
Copy code
fun <F> Mono<A>.toKind(): Kind<F, A> = effect { k().suspended() }
the compiler will find the right specialisation
Copy code
override fun get(): Kind<F, String> = libDBClient.get().toKind()
g
@pakoito I tried this, I hope this is what you meant
Copy code
interface RepoTC<F> : Async<F> {
    fun get(): Kind<F, String>
    
    fun Mono<String>.toKind() = effect { k().suspended()!! }
    fun Single<String>.toKind() = effect { k().suspended() }
}

interface NonBlockingReactorRepo<F> : RepoTC<F> {
    val libDBClient: ReactorLibDBClient

    override fun get(): Kind<F, String> = libDBClient.get().toKind()
}

interface NonBlockingRxRepo<F> : RepoTC<F> {
    val libDBClient: RxLibDBClient

    override fun get(): Kind<F, String> = libDBClient.get().toKind()
}
p
ye
puttint
toKind
in
RepoTC
is kind of an API leak, I’d put them in a top-level object instead
g
Thanks, better than before, but still some repetition, I think that can’t be avoided
But then in the top level, the
effect {}
has to be different in both functions
otherwise has this problem
p
right, you need the effect function to come from async
nevermind then 🙂
g
Ok I think repeating effect in each Typeclass is the only way!
@pakoito