Dealing with multiple sources brings in a new possible scenario: receiving data from multiple Observables, processing them, and making them available as a new Observable sequence. RxJava has a specific method to accomplish this: zip()
combines the value emitted by two or more Observables, transforms them according to a specified function Func*
, and emits a new value. The following figure shows how the zip()
method processes the emitted "numbers" and "letters" and makes them available as a new item:
For our real-world example, we are going to use our installed apps list and a new dynamic Observable to make the example a bit spicy:
Observable<Long> tictoc = Observable.interval(1, TimeUnit.SECONDS);
The tictoc
Observable
variable uses the interval()
function to generate a Long
item every second: simple but effective. As stated previously, we are going to need a Func
object. It will be Func2
because we are going to pass two parameters to it:
private AppInfo updateTitle(AppInfoappInfo,...