June 2017
Intermediate to advanced
400 pages
8h 44m
English
Zipping allows you to take an emission from each Observable source and combine it into a single emission. Each Observable can emit a different type, but you can combine these different emitted types into a single emission. Here is an example, If we have an Observable<String> and an Observable<Integer>, we can zip each String and Integer together in a one-to-one pairing and concatenate it with a lambda:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable<String> source1 = Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon"); Observable<Integer> source2 = Observable.range(1,6); Observable.zip(source1, source2, (s,i) -> s + "-" + i) .subscribe(System.out::println); }}
Read now
Unlock full access