RxJava2 将两个 Flowables 压缩为一个
RxJava2 zip two Flowables into one
我正在努力寻找任何将两个 Flowables 压缩为一个的 RxJava2 示例。
我正在尝试修改 this test 以包含与
类似的内容
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();
编辑:我正在尝试从源和另一个源中获取一个整数并将它们相加,但它似乎与 RxJava1 的做法根本不同......我已经尝试了一系列返回 Integer、Publisher、Flowable 的变体和 void 但在 Eclipse 中关于 zip 运算符本身不断出现错误。
我无法弄清楚 .zip(Iterable<? extends Publisher<? extends T>>, Function<? super Object[], ? extends R>).
中的内容
因为你只需要压缩两个flowables,你可以使用Flowable.zipWith
运算符。
使用方法如下:
source.zipWith(anotherSource, new BiFunction<Integer, Integer, Integer>() {
@Override public Integer apply(Integer a, Integer b) {
return a + b;
}
};
我正在努力寻找任何将两个 Flowables 压缩为一个的 RxJava2 示例。
我正在尝试修改 this test 以包含与
类似的内容 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();
编辑:我正在尝试从源和另一个源中获取一个整数并将它们相加,但它似乎与 RxJava1 的做法根本不同......我已经尝试了一系列返回 Integer、Publisher、Flowable 的变体和 void 但在 Eclipse 中关于 zip 运算符本身不断出现错误。
我无法弄清楚 .zip(Iterable<? extends Publisher<? extends T>>, Function<? super Object[], ? extends R>).
因为你只需要压缩两个flowables,你可以使用Flowable.zipWith
运算符。
使用方法如下:
source.zipWith(anotherSource, new BiFunction<Integer, Integer, Integer>() {
@Override public Integer apply(Integer a, Integer b) {
return a + b;
}
};