Archive Monthly Archives: November 2018

RxJava Operators: concat(), concatWith()

November 8, 2018

concat() The concat() operator is quite similar to merging, but it will not move on to the next Observable until the current one calls onComplete(). This means that the concatenated Observables‘ emissions will be in a guaranteed order. If we would use the concat() operator on infinite Observables, it would keep emitting from the first infinite […]

RxJava Operators: flatMap()

November 7, 2018

flatMap() The flatMap() operator is somewhat similar to the map() operator: the map() operator transforms the emitted items into other items, the flatMap() operators transforms the items into Observables. It performs this by performing a merge() operation (this is the flattening part) on the item after wrapping it into an Observable, thus creating a single stream. […]

RxJava Operators: Merging

November 6, 2018

Operators for merging It is possible to merge multiple Observables into one single Observable. This new Observable will subscribe to all of it’s sources simultaneously. It is possible to merge both finite and infinite Observables. merge() and mergeWith() The operator merge() takes two or more Observable<T> sources and merges them into a single Observable<T>. import io.reactivex.Observable; public class […]

RxJava Operators: doOnSubscribe, doOnSuccess(), doOnDispose() and doFinally()

November 5, 2018

doOnSubscribe, doOnDispose() and doFinally() With the help of the operators doOnSubscribe() and doOnDispose() it is possible to execute code when a subscription and disposal occur: import io.reactivex.Observable; public class Main { public static void main(String[] args) { Observable<String> myObservable = Observable.just(“a”, “b”, “c”, “d”); myObservable.doOnSubscribe(disposable -> System.out.println(“Subscribed!”)) .doOnDispose(() -> System.out.println(“Disposing!”)) .subscribe(System.out::println); } } In the […]