I have two Observables, one Observable<String>
, one Observable<Boolean>
. Can I combine them so I receive
@Override
public void call(String s, Boolean b) {
}
when both operations are finished?
When you want to wait for items 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 an observable generating the application of (a, b) -> a + b
to o1
's and o2
's items. Resulting in an observable yielding "a1", "b2", "c3"
.
You can also use Obervable.zipWith
with an actual instance to get the same effect.
Note that this will terminate on the shorter observable when there is nothing to zip with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With