I am struggling to find any RxJava2 examples of zipping two Flowables into one.
I am trying to modify this test to include something along the lines of
Integer[] ints = new Integer[count];
Integer[] moreints = new Integer[count];
Arrays.fill(ints, 777);
Arrays.fill(moreints, 777);
Flowable<Integer> source = Flowable.fromArray(ints);
Flowable<Integer> anothersource = Flowable.fromArray(moreints);
Flowable<Integer> zippedsources = Flowable.zip(source, anothersource,
new BiFunction<Flowable<Integer>, Flowable<Integer>, Flowable<Integer>>() {
@Override
public void apply(Flowable<Integer> arg0, Flowable<Integer> arg1) throws Exception {
return arg0.blockingFirst() + arg1.blockingLast();
}
}).runOn(Schedulers.computation()).map(this).sequential();
Edit: I am trying to take an Integer from source and anothersource and add them up but it seems fundamentally different from the RxJava1 way of doing that ... I have tried a bunch of variations returning Integer, Publisher, Flowable and void but keep getting and error in Eclipse on the zip operator itself.
I am unable to figure out what goes where in .zip(Iterable<? extends Publisher<? extends T>>, Function<? super Object[], ? extends R>).
Since you only need to zip two flowables, you could use Flowable.zipWith
Operator.
The way it is used is as following:
source.zipWith(anotherSource, new BiFunction<Integer, Integer, Integer>() {
@Override public Integer apply(Integer a, Integer b) {
return a + b;
}
};
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