Gopal S Akshintala
02/26/2020, 12:33 PMRepoTC
and trying to have two families of types NonBlockingRepo
and BlockingRepo
. These families wrap their respective DBClients (Concrete classes coming from a 3rd party implementations and doesn’t have any common hierarchy). In this process, I had to repeat the same code
fx.async { !effect { libDBClient.get().k().suspended() } }
in all NonBlockingRepo
family as shown below. Is there any idiomatic way to avoid repeating this. Thanks
interface RepoTC<F> : Async<F> {
fun get(): Kind<F, String>
}
interface NonBlockingReactorRepo<F> : RepoTC<F> {
val libDBClient: ReactorLibDBClient
override fun get(): Kind<F, String> = fx.async { !effect { libDBClient.get().k().suspended()!! } }
}
interface NonBlockingRxRepo<F> : RepoTC<F> {
val libDBClient: RxLibDBClient
override fun get(): Kind<F, String> = fx.async { !effect { libDBClient.get().k().suspended() } }
}
interface BlockingRepo<F> : RepoTC<F> {
val libDBClient: BlockingLibDBClient
override fun get(): Kind<F, String> = fx.async { libDBClient.get() }
}
/* Concrete 3rd party Lib Impls */
class ReactorLibDBClient {
fun get(): Mono<String> = Mono.just("from mono")
}
class RxLibDBClient {
fun get(): Single<String> = Single.just("from Rx Single")
}
class BlockingLibDBClient {
fun get() = "from blocking"
}