Combine two observables that emit different types

I have two observables, one Observable<String> , one Observable<Boolean> . Can i combine them to get

 @Override public void call(String s, Boolean b) { } 

When are both operations completed?

+6
source share
1 answer

If you want to wait for the elements to be emitted from two observables (synchronizing them), you usually want something like Observable.zip :

 Observable<String> o1 = Observable.just("a", "b", "c"); Observable<Integer> o2 = Observable.just(1, 2, 3); Observable<String> result = Observable.zip(o1, o2, (a, b) -> a + b); 

result will be observable, generating the use of elements (a, b) -> a + b to o1 and o2 . As a result, the observed income is "a1", "b2", "c3" .

You can also use Obervable.zipWith with the actual instance to get the same effect.

Note that this will be completed on a shorter observable if you do nothing zip with.

+13
source

All Articles