Skip to content

Commit ea16550

Browse files
committed
Adding zip(Ob<Ob<?>>)
1 parent 8345dc7 commit ea16550

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,66 @@ public R call(T0 t0, T1 t1, T2 t2, T3 t3) {
26472647
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
26482648
*
26492649
* @param ws
2650-
* A collection of source Observable
2650+
* An Observable of source Observables
2651+
* @param reduceFunction
2652+
* a function that, when applied to an item emitted by each of the source
2653+
* Observables, results in an item that will be emitted by the resulting Observable
2654+
* @return an Observable that emits the zipped results
2655+
*/
2656+
public static <R> Observable<R> zip(Observable<Observable<?>> ws, final FuncN<R> reduceFunction) {
2657+
return ws.toList().mapMany(new Func1<List<Observable<?>>, Observable<R>>() {
2658+
@Override
2659+
public Observable<R> call(List<Observable<?>> wsList) {
2660+
return create(OperationZip.zip(wsList, reduceFunction));
2661+
}
2662+
});
2663+
}
2664+
2665+
/**
2666+
* Returns an Observable that emits the results of a function of your choosing applied to
2667+
* combinations of four items emitted, in sequence, by four other Observables.
2668+
* <p>
2669+
* <code>zip</code> applies this function in strict sequence, so the first item emitted by the
2670+
* new Observable will be the result of the function applied to the first item emitted by
2671+
* all of the Observalbes; the second item emitted by the new Observable will be the result of
2672+
* the function applied to the second item emitted by each of those Observables; and so forth.
2673+
* <p>
2674+
* The resulting <code>Observable<R></code> returned from <code>zip</code> will invoke
2675+
* <code>onNext</code> as many times as the number of <code>onNext</code> invocations of the
2676+
* source Observable that emits the fewest items.
2677+
* <p>
2678+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
2679+
*
2680+
* @param ws
2681+
* An Observable of source Observables
2682+
* @param function
2683+
* a function that, when applied to an item emitted by each of the source
2684+
* Observables, results in an item that will be emitted by the resulting Observable
2685+
* @return an Observable that emits the zipped results
2686+
*/
2687+
public static <R> Observable<R> zip(Observable<Observable<?>> ws, final Object function) {
2688+
@SuppressWarnings({ "unchecked" })
2689+
final FuncN<R> _f = Functions.from(function);
2690+
return zip(ws, _f);
2691+
}
2692+
2693+
/**
2694+
* Returns an Observable that emits the results of a function of your choosing applied to
2695+
* combinations of four items emitted, in sequence, by four other Observables.
2696+
* <p>
2697+
* <code>zip</code> applies this function in strict sequence, so the first item emitted by the
2698+
* new Observable will be the result of the function applied to the first item emitted by
2699+
* all of the Observalbes; the second item emitted by the new Observable will be the result of
2700+
* the function applied to the second item emitted by each of those Observables; and so forth.
2701+
* <p>
2702+
* The resulting <code>Observable<R></code> returned from <code>zip</code> will invoke
2703+
* <code>onNext</code> as many times as the number of <code>onNext</code> invokations of the
2704+
* source Observable that emits the fewest items.
2705+
* <p>
2706+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
2707+
*
2708+
* @param ws
2709+
* A collection of source Observables
26512710
* @param reduceFunction
26522711
* a function that, when applied to an item emitted by each of the source
26532712
* Observables, results in an item that will be emitted by the resulting Observable
@@ -2673,7 +2732,7 @@ public static <R> Observable<R> zip(Collection<Observable<?>> ws, FuncN<R> reduc
26732732
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
26742733
*
26752734
* @param ws
2676-
* A collection of source Observable
2735+
* A collection of source Observables
26772736
* @param function
26782737
* a function that, when applied to an item emitted by each of the source
26792738
* Observables, results in an item that will be emitted by the resulting Observable

0 commit comments

Comments
 (0)