Composing Observables
As we explained earlier, an Observable
interface is defined in a way that allows us to chain and combine different Observables
to create complex tasks in a functional and declarative way.
Starting from our previous work, in our next example, we will make use of the RxJava
composing feature and execute a second network call that depends on the previous Observable
that will translate the text downloaded using a web service before we emit the translated text to the Subscriber
.
To execute the translation on the network on a logically separate unit, we will create a new Observable
that receives the text to translate, executes the task on the network, and emits the translated text as a String to the following Observable
:
Observable<String> translateOnNetwork(final String url, final String toTranslate) { return Observable.create( new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<...