) : ImageFlickrRepository { override fun findByText(searchOrderType: SearchOrderType, text: String, page: Int, perPage: Int): Observable<List<MaterialPhoto>> { return remote.findByText(searchOrderType, text, page, perPage) .observeOn(Schedulers.newThread()) .doOnNext { p: List<FlickrPhoto> -> local.updateCache(searchOrderType, text, page, p) } .filter{ photos -> !photos.isEmpty()} .first(ArrayList()) .toObservable() .observeOn(AndroidSchedulers.mainThread()) .map { MaterialImageMapper.transform(it) } } override fun findById(materialPhotoId: MaterialPhotoId): Observable<MaterialPhoto> {} override fun clearCache(searchOrderType: SearchOrderType, text: String): Single<Int> {} } Repository Impl class ImageFlickrRepositoryImpl( private val remote: ImageFlickrDataSource, private val local: ImageFlickrDataSource ) : ImageFlickrRepository { override fun findByText(searchOrderType: SearchOrderType, text: String, page: Int, perPage: Int): Observable<List<MaterialPhoto>> { return remote.findByText(searchOrderType, text, page, perPage) .observeOn(Schedulers.newThread()) .doOnNext { p: List<FlickrPhoto> -> local.updateCache(searchOrderType, text, page, p) } .filter{ photos -> !photos.isEmpty()} .first(ArrayList()) .toObservable() .observeOn(AndroidSchedulers.mainThread()) .map { MaterialImageMapper.transform(it) } } override fun findById(materialPhotoId: MaterialPhotoId): Observable<MaterialPhoto> {} override fun clearCache(searchOrderType: SearchOrderType, text: String): Single<Int> {} }