Wednesday 17 January 2018

Operator - CombineLatest




CombineLatest

when an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function





The CombineLatest operator behaves in a similar way to Zip, but while Zip emits items only when each of the zipped source Observables have emitted a previously unzipped item, CombineLatest emits an item whenever any of the source Observables emits an item (so long as each of the source Observables has emitted at least one item). When any of the source Observables emits an item, CombineLatest combines the most recently emitted items from each of the other source Observables, using a function you provide, and emits the return value from that function.



Code - 

-------------------------------------------------------------------------------------


        Observable<Integer> intObs = Observable.just(1, 2, 3, 4, 5);
        Observable<String> stringObs = Observable.just("One");
        Observable<String> stringObs2 = Observable.just("Two");

        Observable.combineLatest(intObs, stringObs, stringObs2,
                (i, s, s2) -> "Observable 1: " + i + " " + s + " " + s2)
                .blockingIterable()
                .forEach(System.out::println);

        Observable.combineLatest(stringObs, stringObs2, intObs,
                (s, s2, i) -> "Observable 2: " + i + " " + s + " " + s2)
                .blockingIterable()
                .forEach(System.out::println);


-------------------------------------------------------------------------------------







22

No comments:

Post a Comment

Calling method Sequencely

1. Execute multiple task sequencly (WAY-1) ------------------------------------------------------------------------------ import io.re...