I'm writing an API client in Android using Retrofit and this sort of code gets repeated a lot:
myObservableFromRetrofit
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(... print stack trace ...)
I'm wondering if there is a technique to avoid repeating this stuff.
I surrounding calls to retrofit functions with:
public Observable<?> commonObservable(Observable<?> observable) {
return observable
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(... print stack trace ...)
}
But that loses generics type information.