I would like to build a Repository
class that returns a Single<Something>
.
The class should first look in a Cache
which returns Maybe<Something>
and if the Maybe
completes go off to my Service
that returns Single<Something>
interface Cache {
fun getSomething(): Maybe<Something>
}
interface Service {
fun getSomething(): Single<Something>
}
class Repository (
private val cache: Cache,
private val service: Service
) {
fun getSomething(): Single<Something> {
return cache.getSomething()
.????(feed.getSomething()) //onCompleteTransformToSingle() or similar
}
}
我已经搜索了JavaDoc,但似乎不存在这种情况下的转换器.
Is there a nice way of handling this?