【发布时间】:2017-10-09 15:21:01
【问题描述】:
我正在努力寻找将两个 Flowable 压缩为一个的任何 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>). 中的内容是什么
【问题讨论】:
-
你期待什么结果,你现在有什么结果?
-
尝试
BiFunction<Integer, Integer, Integer>并调整apply方法的类型。压缩函数获取的不是源Flowables,而是每次调用一个值。 -
谢谢@akarnokd - 这正是我的误解。