From ea165508aa83e4d9bb7174d0a2ec8450932e4908 Mon Sep 17 00:00:00 2001 From: George Campbell Date: Mon, 17 Jun 2013 16:27:04 -0700 Subject: [PATCH] Adding zip(Ob>) --- rxjava-core/src/main/java/rx/Observable.java | 63 +++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/rxjava-core/src/main/java/rx/Observable.java b/rxjava-core/src/main/java/rx/Observable.java index 42a3066de9..5e523d794b 100644 --- a/rxjava-core/src/main/java/rx/Observable.java +++ b/rxjava-core/src/main/java/rx/Observable.java @@ -2647,7 +2647,66 @@ public R call(T0 t0, T1 t1, T2 t2, T3 t3) { * * * @param ws - * A collection of source Observable + * An Observable of source Observables + * @param reduceFunction + * a function that, when applied to an item emitted by each of the source + * Observables, results in an item that will be emitted by the resulting Observable + * @return an Observable that emits the zipped results + */ + public static Observable zip(Observable> ws, final FuncN reduceFunction) { + return ws.toList().mapMany(new Func1>, Observable>() { + @Override + public Observable call(List> wsList) { + return create(OperationZip.zip(wsList, reduceFunction)); + } + }); + } + + /** + * Returns an Observable that emits the results of a function of your choosing applied to + * combinations of four items emitted, in sequence, by four other Observables. + *

+ * zip applies this function in strict sequence, so the first item emitted by the + * new Observable will be the result of the function applied to the first item emitted by + * all of the Observalbes; the second item emitted by the new Observable will be the result of + * the function applied to the second item emitted by each of those Observables; and so forth. + *

+ * The resulting Observable returned from zip will invoke + * onNext as many times as the number of onNext invocations of the + * source Observable that emits the fewest items. + *

+ * + * + * @param ws + * An Observable of source Observables + * @param function + * a function that, when applied to an item emitted by each of the source + * Observables, results in an item that will be emitted by the resulting Observable + * @return an Observable that emits the zipped results + */ + public static Observable zip(Observable> ws, final Object function) { + @SuppressWarnings({ "unchecked" }) + final FuncN _f = Functions.from(function); + return zip(ws, _f); + } + + /** + * Returns an Observable that emits the results of a function of your choosing applied to + * combinations of four items emitted, in sequence, by four other Observables. + *

+ * zip applies this function in strict sequence, so the first item emitted by the + * new Observable will be the result of the function applied to the first item emitted by + * all of the Observalbes; the second item emitted by the new Observable will be the result of + * the function applied to the second item emitted by each of those Observables; and so forth. + *

+ * The resulting Observable returned from zip will invoke + * onNext as many times as the number of onNext invokations of the + * source Observable that emits the fewest items. + *

+ * + * + * @param ws + * A collection of source Observables * @param reduceFunction * a function that, when applied to an item emitted by each of the source * Observables, results in an item that will be emitted by the resulting Observable @@ -2673,7 +2732,7 @@ public static Observable zip(Collection> ws, FuncN reduc * * * @param ws - * A collection of source Observable + * A collection of source Observables * @param function * a function that, when applied to an item emitted by each of the source * Observables, results in an item that will be emitted by the resulting Observable