June 2017
Intermediate to advanced
400 pages
8h 44m
English
If you have a finite Observable<T> emitting items that implement Comparable<T>, you can use sorted() to sort the emissions. Internally, it will collect all the emissions and then re-emit them in their sorted order. In the following code snippet, we sort emissions from Observable<Integer>so that they are emitted in their natural order:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just(6, 2, 5, 7, 1, 4, 9, 8, 3) .sorted() .subscribe(System.out::println); }}
The output of the preceding code snippet is as follows:
123456789
Of course, this can have some performance implications as it will collect all emissions in memory before emitting them again. If you use this against an ...
Read now
Unlock full access