I realize this may fall under the scope of library design and feature implementation, but wanted to ask if there is any way we can use Transformers on different sources (Observable and Completable for instance), as they share quite a lot of methods, particularly side effects. Instead of creating our own operators by extending them, we have created transformers to handle the logic we commonly use with our observables and completables.
For instance, instead of wrapping the disposable returned on subscribe call, we have created a Transformer function for it:
public static <T> ObservableTransformer<T, T> dispose(CompositeDisposable compositeDisposable) {
return observable -> observable.doOnSubscribe(compositeDisposable::add);
}
Now, this won't work on any other source than Observable, we needed to add another method for completable
public static CompletableTransformer disposeCompletable(CompositeDisposable compositeDisposable) {
return completable -> completable.doOnSubscribe(compositeDisposable::add);
}
This has become a pattern around handling just 2 different source's transformers which have exactly same methods
For instance
public static <T, V extends Progressive & Erroneous> ObservableTransformer<T, T> progressiveErroneous(V view) {
return observable -> observable
.compose(progressive(view))
.compose(erroneous(view));
}
public static <V extends Progressive & Erroneous> CompletableTransformer progressiveErroneousCompletable(V view) {
return observable -> observable
.compose(progressiveCompletable(view))
.compose(erroneousCompletable(view));
}
For these, we had to implement progressiveCompletable(view) and erroneousCompletable(view), with no difference in method body.
We also want to remove testing from our controllers and just tests these transformers calling correct methods on view interfaces. This will drastically reduce redundant tests, and that's the reason why we opted for such abstract design. But if we keep duplicating methods like this, the tests will be very repetitive. And if we start using other sources such as Flowable, Maybe, etc, it'll only get worse
Is there any way we can use abstract transformers which operate on range of sources which support common operations like
- doOnSubscribe
- doOnError
- doFinally
- etc