O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Combine latest

Another useful operator to know is .combineLatest(). It can be used to merge items from multiple Observables in a very similar way that .zip() is used, but instead of waiting for values to be produced by both the Observables, it produces new values every time one of the Observables emits an item.

When a value is produced from one of the Observable, the previous value of the other Observable is retrieved and instantly a new item from .combineLatest() is produced.

Let's explore an example:

Observable.combineLatest(        Observable.just("One", "Two", "Three"),        Observable.interval(1, TimeUnit.SECONDS),        (number, interval) -> number + "-" + interval)        .subscribe(e -> log("subscribe", e));

This will produce the following output:

 APP: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required