Skip to content

Commit f8f378f

Browse files
Merge pull request ReactiveX#370 from benjchristensen/zip-collection-to-iterable
Change zip method signature from Collection to Iterable
2 parents a0f4b30 + 5386480 commit f8f378f

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,29 +1891,6 @@ public static <T> Observable<T> from(Future<? extends T> future, long timeout, T
18911891
return create(OperationToObservableFuture.toObservableFuture(future, timeout, unit));
18921892
}
18931893

1894-
/**
1895-
* <p>
1896-
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
1897-
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
1898-
* 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
1899-
* 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.
1900-
* <p>
1901-
* 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
1902-
* of the source Observable that emits the fewest items.
1903-
*
1904-
* @param o1
1905-
* one source Observable
1906-
* @param o2
1907-
* another source Observable
1908-
* @param zipFunction
1909-
* a function that, when applied to an item emitted by each of the source
1910-
* Observables, results in an item that will be emitted by the resulting Observable
1911-
* @return an Observable that emits the zipped results
1912-
*/
1913-
public static <T1, T2, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> zipFunction) {
1914-
return create(OperationZip.zip(o1, o2, zipFunction));
1915-
}
1916-
19171894
/**
19181895
* Returns an Observable that emits Boolean values that indicate whether the pairs of items
19191896
* emitted by two source Observables are equal.
@@ -1960,6 +1937,31 @@ public static <T> Observable<Boolean> sequenceEqual(Observable<? extends T> firs
19601937
return zip(first, second, equality);
19611938
}
19621939

1940+
/**
1941+
* Returns an Observable that emits the results of a function of your choosing applied to
1942+
* combinations of two items emitted, in sequence, by two other Observables.
1943+
* <p>
1944+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
1945+
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
1946+
* 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
1947+
* 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.
1948+
* <p>
1949+
* 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
1950+
* of the source Observable that emits the fewest items.
1951+
*
1952+
* @param o1
1953+
* one source Observable
1954+
* @param o2
1955+
* another source Observable
1956+
* @param zipFunction
1957+
* a function that, when applied to an item emitted by each of the source
1958+
* Observables, results in an item that will be emitted by the resulting Observable
1959+
* @return an Observable that emits the zipped results
1960+
*/
1961+
public static <T1, T2, R> Observable<R> zip(Observable<? extends T1> o1, Observable<? extends T2> o2, Func2<? super T1, ? super T2, ? extends R> zipFunction) {
1962+
return create(OperationZip.zip(o1, o2, zipFunction));
1963+
}
1964+
19631965
/**
19641966
* Returns an Observable that emits the results of a function of your choosing applied to
19651967
* combinations of three items emitted, in sequence, by three other Observables.
@@ -2021,7 +2023,7 @@ public static <T1, T2, T3, T4, R> Observable<R> zip(Observable<? extends T1> o1,
20212023

20222024
/**
20232025
* Returns an Observable that emits the results of a function of your choosing applied to
2024-
* combinations of four items emitted, in sequence, by four other Observables.
2026+
* combinations of five items emitted, in sequence, by five other Observables.
20252027
* <p>
20262028
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
20272029
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
@@ -2054,7 +2056,7 @@ public static <T1, T2, T3, T4, T5, R> Observable<R> zip(Observable<? extends T1>
20542056

20552057
/**
20562058
* Returns an Observable that emits the results of a function of your choosing applied to
2057-
* combinations of four items emitted, in sequence, by four other Observables.
2059+
* combinations of six items emitted, in sequence, by six other Observables.
20582060
* <p>
20592061
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
20602062
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
@@ -2090,7 +2092,7 @@ public static <T1, T2, T3, T4, T5, T6, R> Observable<R> zip(Observable<? extends
20902092

20912093
/**
20922094
* Returns an Observable that emits the results of a function of your choosing applied to
2093-
* combinations of four items emitted, in sequence, by four other Observables.
2095+
* combinations of seven items emitted, in sequence, by seven other Observables.
20942096
* <p>
20952097
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
20962098
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
@@ -2128,7 +2130,7 @@ public static <T1, T2, T3, T4, T5, T6, T7, R> Observable<R> zip(Observable<? ext
21282130

21292131
/**
21302132
* Returns an Observable that emits the results of a function of your choosing applied to
2131-
* combinations of four items emitted, in sequence, by four other Observables.
2133+
* combinations of eight items emitted, in sequence, by eight other Observables.
21322134
* <p>
21332135
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
21342136
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
@@ -2168,7 +2170,7 @@ public static <T1, T2, T3, T4, T5, T6, T7, T8, R> Observable<R> zip(Observable<?
21682170

21692171
/**
21702172
* Returns an Observable that emits the results of a function of your choosing applied to
2171-
* combinations of four items emitted, in sequence, by four other Observables.
2173+
* combinations of nine items emitted, in sequence, by nine other Observables.
21722174
* <p>
21732175
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/zip.png">
21742176
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
@@ -2680,7 +2682,8 @@ public Observable<Observable<T>> window(long timespan, long timeshift, TimeUnit
26802682

26812683
/**
26822684
* Returns an Observable that emits the results of a function of your choosing applied to
2683-
* combinations of four items emitted, in sequence, by four other Observables.
2685+
* combinations of N items emitted, in sequence, by N other Observables as provided by an Iterable.
2686+
*
26842687
* <p> {@code zip} applies this function in strict sequence, so the first item emitted by the
26852688
* new Observable will be the result of the function applied to the first item emitted by
26862689
* all of the Observalbes; the second item emitted by the new Observable will be the result of
@@ -2727,7 +2730,7 @@ public Observable<R> call(List<? extends Observable<?>> wsList) {
27272730
* Observables, results in an item that will be emitted by the resulting Observable
27282731
* @return an Observable that emits the zipped results
27292732
*/
2730-
public static <R> Observable<R> zip(Collection<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
2733+
public static <R> Observable<R> zip(Iterable<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
27312734
return create(OperationZip.zip(ws, zipFunction));
27322735
}
27332736

rxjava-core/src/main/java/rx/operators/OperationZip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> OnSubscribeFunc<R> zip(Obs
147147
return a;
148148
}
149149

150-
public static <R> OnSubscribeFunc<R> zip(Collection<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
150+
public static <R> OnSubscribeFunc<R> zip(Iterable<? extends Observable<?>> ws, FuncN<? extends R> zipFunction) {
151151
Aggregator<R> a = new Aggregator<R>(zipFunction);
152152
for (Observable<?> w : ws) {
153153
ZipObserver<R, Object> zipObserver = new ZipObserver<R, Object>(a, w);

0 commit comments

Comments
 (0)