RxJava Operators: withLatestFrom()

November 13, 2018


The operator withLatestFrom() is quite similar to combineLatest(): it maps each emission with the latest value from the other Observables and combines them.
The key difference compared to combineLatest() is that it will take only one emission from each Observable.

import io.reactivex.Observable;

public class Main {

    public static void main(String[] args)  {
        Observable<String> mySource1 = Observable.just("a", "b", "c", "d", "e");

        Observable<String> mySource2 = Observable.just("x");

        Observable<String> mySource3 = Observable.just("y");

        mySource2.withLatestFrom(mySource1, mySource3,
                                (s2, s1, s3) -> String.format("%s - %s - %s", s1, s2, s3))
András Döbröntey

About the Author

András Döbröntey

Leave a Comment: