Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RxJava2将两个Flowables压缩为一个_Java_Rx Java2_Reactivex - Fatal编程技术网

RxJava2将两个Flowables压缩为一个

RxJava2将两个Flowables压缩为一个,java,rx-java2,reactivex,Java,Rx Java2,Reactivex,我正在努力寻找将两个FlowTables压缩为一个的RxJava2示例 我正在尝试修改,以包含一些与 Integer[] ints = new Integer[count]; Integer[] moreints = new Integer[count]; Arrays.fill(ints, 777); Arrays.fill(moreints, 777); Flowable<Integer> source = Flowable.fromAr

我正在努力寻找将两个FlowTables压缩为一个的RxJava2示例

我正在尝试修改,以包含一些与

    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();
Integer[]ints=新整数[count];
整数[]moreints=新整数[计数];
数组。填充(整数,777);
数组。填充(moreints,777);
可流动源=可流动的.fromArray(整数);
可流动的另一个源=可流动的.fromArray(moreints);
Flowable zippedsources=Flowable.zip(源,另一个源,
新的双函数(){
@凌驾
公共void apply(可流动arg0、可流动arg1)引发异常{
返回arg0.blockingFirst()+arg1.blockingLast();
}
}).runOn(Schedulers.computation()).map(this.sequential();
编辑:我试图从一个源代码和另一个源代码中获取一个整数,并将它们相加,但这似乎与RxJava1的方法有根本的不同。。。我尝试了一系列返回Integer、Publisher、Flowable和void的变体,但在Eclipse中,zip操作符本身不断出现错误


我无法计算出
.zip(Iterable中的内容,因为您只需要压缩两个Flowable,所以可以使用
Flowable.zipWith
操作符

其使用方式如下:

source.zipWith(anotherSource, new BiFunction<Integer, Integer, Integer>() {
    @Override public Integer apply(Integer a, Integer b) {
        return a + b;
    } 
};
source.zipWith(另一个源代码,新的双函数(){
@覆盖公共整数应用(整数a、整数b){
返回a+b;
} 
};

您希望得到什么样的结果?现在有什么结果?请尝试
BiFunction
,并调整
apply
方法的类型。压缩函数不会得到源
Flowable
s,而是每次调用一个值。谢谢@akarnokd-这正是我的误解。谢谢
BiFunction