2017-08-08 41 views

回答

5

便利性和背景。

静态zip是有用的,当你有两个来源已经汇编,现在你想把它们压缩在一起。大多数时候,他们本身就是长链,或者来自全国各地。

Observable<T1> source1 = op().op().op().op().op(); 
Observable<T2> source2 = op().op().op().op().op(); 

Observable.zip(source1, source2, (a, b) -> a + b); 

实例zipWith时的来源之一是较长的,而另一个是短是有用的。那时,用较短的一个拉链更方便。

public Observable<R> withIndex(Observable<T> source, Func2<Integer, T, R> func) { 
    return source.zipWith(Observable.range(0, Integer.MAX_VALUE), 
     (t, idx) -> func(idx, t)); 
} 
相关问题