Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change zip method signature from Collection to Iterable #370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1891,29 +1891,6 @@ public static <T> Observable<T> from(Future<? extends T> future, long timeout, T
return create(OperationToObservableFuture.toObservableFuture(future, timeout, unit));
}

/**
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
* <p> {@code 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 {@code w0} and the first item emitted by {@code w1}; the second item emitted by
* the new Observable will be the result of the function applied to the second item emitted by {@code w0} and the second item emitted by {@code w1}; and so forth.
* <p>
* The resulting {@code Observable<R>} returned from {@code zip} will invoke {@link Observer#onNext onNext} as many times as the number of {@code onNext} invocations
* of the source Observable that emits the fewest items.
*
* @param o1
* one source Observable
* @param o2
* another source Observable
* @param zipFunction
* 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 <T1, T2, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> zipFunction) {
return create(OperationZip.zip(o1, o2, zipFunction));
}

/**
* Returns an Observable that emits Boolean values that indicate whether the pairs of items
* emitted by two source Observables are equal.
Expand Down Expand Up @@ -1960,6 +1937,31 @@ public static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> firs
return zip(first, second, equality);
}

/**
* Returns an Observable that emits the results of a function of your choosing applied to
* combinations of two items emitted, in sequence, by two other Observables.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
* <p> {@code 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 {@code w0} and the first item emitted by {@code w1}; the second item emitted by
* the new Observable will be the result of the function applied to the second item emitted by {@code w0} and the second item emitted by {@code w1}; and so forth.
* <p>
* The resulting {@code Observable<R>} returned from {@code zip} will invoke {@link Observer#onNext onNext} as many times as the number of {@code onNext} invocations
* of the source Observable that emits the fewest items.
*
* @param o1
* one source Observable
* @param o2
* another source Observable
* @param zipFunction
* 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 <T1, T2, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> zipFunction) {
return create(OperationZip.zip(o1, o2, zipFunction));
}

/**
* Returns an Observable that emits the results of a function of your choosing applied to
* combinations of three items emitted, in sequence, by three other Observables.
Expand Down Expand Up @@ -2021,7 +2023,7 @@ public static <T1, T2, T3, T4, R> Observable<R> zip(Observable<? extends T1> o1,

/**
* 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.
* combinations of five items emitted, in sequence, by five other Observables.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
Expand Down Expand Up @@ -2054,7 +2056,7 @@ public static <T1, T2, T3, T4, T5, R> Observable<R> zip(Observable<? extends T1>

/**
* 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.
* combinations of six items emitted, in sequence, by six other Observables.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
Expand Down Expand Up @@ -2090,7 +2092,7 @@ public static <T1, T2, T3, T4, T5, T6, R> Observable<R> zip(Observable<? extends

/**
* 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.
* combinations of seven items emitted, in sequence, by seven other Observables.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
Expand Down Expand Up @@ -2128,7 +2130,7 @@ public static <T1, T2, T3, T4, T5, T6, T7, R> Observable<R> zip(Observable<? ext

/**
* 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.
* combinations of eight items emitted, in sequence, by eight other Observables.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
Expand Down Expand Up @@ -2168,7 +2170,7 @@ public static <T1, T2, T3, T4, T5, T6, T7, T8, R> Observable<R> zip(Observable<?

/**
* 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.
* combinations of nine items emitted, in sequence, by nine other Observables.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
Expand Down Expand Up @@ -2680,7 +2682,8 @@ public Observable<Observable<T>> window(long timespan, long timeshift, TimeUnit

/**
* 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.
* combinations of N items emitted, in sequence, by N other Observables as provided by an Iterable.
*
* <p> {@code 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
Expand Down Expand Up @@ -2727,7 +2730,7 @@ public Observable<R> call(List<? extends Observable<?>> wsList) {
* Observables, results in an item that will be emitted by the resulting Observable
* @return an Observable that emits the zipped results
*/
public static <R> Observable<R> zip(Collection<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
public static <R> Observable<R> zip(Iterable<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
return create(OperationZip.zip(ws, zipFunction));
}

Expand Down
2 changes: 1 addition & 1 deletion rxjava-core/src/main/java/rx/operators/OperationZip.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> OnSubscribeFunc<R> zip(Obs
return a;
}

public static <R> OnSubscribeFunc<R> zip(Collection<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
public static <R> OnSubscribeFunc<R> zip(Iterable<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
Aggregator<R> a = new Aggregator<R>(zipFunction);
for (Observable<?> w : ws) {
ZipObserver<R, Object> zipObserver = new ZipObserver<R, Object>(a, w);
Expand Down