Skip to content

Commit f5716b4

Browse files
No more need to convert Singles to Observables for Single.zip()
1 parent 8d3a0c5 commit f5716b4

File tree

2 files changed

+297
-74
lines changed

2 files changed

+297
-74
lines changed

src/main/java/rx/Single.java

Lines changed: 105 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -956,18 +956,23 @@ public final static <T> Observable<T> merge(Single<? extends T> t1, Single<? ext
956956
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
957957
* </dl>
958958
*
959-
* @param o1
959+
* @param s1
960960
* the first source Single
961-
* @param o2
961+
* @param s2
962962
* a second source Single
963963
* @param zipFunction
964964
* a function that, when applied to the item emitted by each of the source Singles, results in an
965965
* item that will be emitted by the resulting Single
966966
* @return a Single that emits the zipped results
967967
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
968968
*/
969-
public final static <T1, T2, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, final Func2<? super T1, ? super T2, ? extends R> zipFunction) {
970-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2) }).lift(new OperatorZip<R>(zipFunction));
969+
public static final <T1, T2, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, final Func2<? super T1, ? super T2, ? extends R> zipFunction) {
970+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2}, new FuncN<R>() {
971+
@Override
972+
public R call(Object... args) {
973+
return zipFunction.call((T1) args[0], (T2) args[1]);
974+
}
975+
});
971976
}
972977

973978
/**
@@ -980,20 +985,25 @@ public final static <T1, T2, R> Single<R> zip(Single<? extends T1> o1, Single<?
980985
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
981986
* </dl>
982987
*
983-
* @param o1
988+
* @param s1
984989
* the first source Single
985-
* @param o2
990+
* @param s2
986991
* a second source Single
987-
* @param o3
992+
* @param s3
988993
* a third source Single
989994
* @param zipFunction
990995
* a function that, when applied to the item emitted by each of the source Singles, results in an
991996
* item that will be emitted by the resulting Single
992997
* @return a Single that emits the zipped results
993998
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
994999
*/
995-
public final static <T1, T2, T3, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, Single<? extends T3> o3, Func3<? super T1, ? super T2, ? super T3, ? extends R> zipFunction) {
996-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3) }).lift(new OperatorZip<R>(zipFunction));
1000+
public static final <T1, T2, T3, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, final Func3<? super T1, ? super T2, ? super T3, ? extends R> zipFunction) {
1001+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3}, new FuncN<R>() {
1002+
@Override
1003+
public R call(Object... args) {
1004+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2]);
1005+
}
1006+
});
9971007
}
9981008

9991009
/**
@@ -1006,22 +1016,27 @@ public final static <T1, T2, T3, R> Single<R> zip(Single<? extends T1> o1, Singl
10061016
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
10071017
* </dl>
10081018
*
1009-
* @param o1
1019+
* @param s1
10101020
* the first source Single
1011-
* @param o2
1021+
* @param s2
10121022
* a second source Single
1013-
* @param o3
1023+
* @param s3
10141024
* a third source Single
1015-
* @param o4
1025+
* @param s4
10161026
* a fourth source Single
10171027
* @param zipFunction
10181028
* a function that, when applied to the item emitted by each of the source Singles, results in an
10191029
* item that will be emitted by the resulting Single
10201030
* @return a Single that emits the zipped results
10211031
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
10221032
*/
1023-
public final static <T1, T2, T3, T4, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, Single<? extends T3> o3, Single<? extends T4> o4, Func4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> zipFunction) {
1024-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3), asObservable(o4) }).lift(new OperatorZip<R>(zipFunction));
1033+
public static final <T1, T2, T3, T4, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, final Func4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> zipFunction) {
1034+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4}, new FuncN<R>() {
1035+
@Override
1036+
public R call(Object... args) {
1037+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2], (T4) args[3]);
1038+
}
1039+
});
10251040
}
10261041

10271042
/**
@@ -1034,24 +1049,29 @@ public final static <T1, T2, T3, T4, R> Single<R> zip(Single<? extends T1> o1, S
10341049
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
10351050
* </dl>
10361051
*
1037-
* @param o1
1052+
* @param s1
10381053
* the first source Single
1039-
* @param o2
1054+
* @param s2
10401055
* a second source Single
1041-
* @param o3
1056+
* @param s3
10421057
* a third source Single
1043-
* @param o4
1058+
* @param s4
10441059
* a fourth source Single
1045-
* @param o5
1060+
* @param s5
10461061
* a fifth source Single
10471062
* @param zipFunction
10481063
* a function that, when applied to the item emitted by each of the source Singles, results in an
10491064
* item that will be emitted by the resulting Single
10501065
* @return a Single that emits the zipped results
10511066
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
10521067
*/
1053-
public final static <T1, T2, T3, T4, T5, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, Single<? extends T3> o3, Single<? extends T4> o4, Single<? extends T5> o5, Func5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> zipFunction) {
1054-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3), asObservable(o4), asObservable(o5) }).lift(new OperatorZip<R>(zipFunction));
1068+
public static final <T1, T2, T3, T4, T5, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, final Func5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> zipFunction) {
1069+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4, s5}, new FuncN<R>() {
1070+
@Override
1071+
public R call(Object... args) {
1072+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2], (T4) args[3], (T5) args[4]);
1073+
}
1074+
});
10551075
}
10561076

10571077
/**
@@ -1064,27 +1084,32 @@ public final static <T1, T2, T3, T4, T5, R> Single<R> zip(Single<? extends T1> o
10641084
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
10651085
* </dl>
10661086
*
1067-
* @param o1
1087+
* @param s1
10681088
* the first source Single
1069-
* @param o2
1089+
* @param s2
10701090
* a second source Single
1071-
* @param o3
1091+
* @param s3
10721092
* a third source Single
1073-
* @param o4
1093+
* @param s4
10741094
* a fourth source Single
1075-
* @param o5
1095+
* @param s5
10761096
* a fifth source Single
1077-
* @param o6
1097+
* @param s6
10781098
* a sixth source Single
10791099
* @param zipFunction
10801100
* a function that, when applied to the item emitted by each of the source Singles, results in an
10811101
* item that will be emitted by the resulting Single
10821102
* @return a Single that emits the zipped results
10831103
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
10841104
*/
1085-
public final static <T1, T2, T3, T4, T5, T6, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, Single<? extends T3> o3, Single<? extends T4> o4, Single<? extends T5> o5, Single<? extends T6> o6,
1086-
Func6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> zipFunction) {
1087-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3), asObservable(o4), asObservable(o5), asObservable(o6) }).lift(new OperatorZip<R>(zipFunction));
1105+
public static final <T1, T2, T3, T4, T5, T6, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6,
1106+
final Func6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> zipFunction) {
1107+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4, s5, s6}, new FuncN<R>() {
1108+
@Override
1109+
public R call(Object... args) {
1110+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2], (T4) args[3], (T5) args[4], (T6) args[5]);
1111+
}
1112+
});
10881113
}
10891114

10901115
/**
@@ -1097,29 +1122,34 @@ public final static <T1, T2, T3, T4, T5, T6, R> Single<R> zip(Single<? extends T
10971122
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
10981123
* </dl>
10991124
*
1100-
* @param o1
1125+
* @param s1
11011126
* the first source Single
1102-
* @param o2
1127+
* @param s2
11031128
* a second source Single
1104-
* @param o3
1129+
* @param s3
11051130
* a third source Single
1106-
* @param o4
1131+
* @param s4
11071132
* a fourth source Single
1108-
* @param o5
1133+
* @param s5
11091134
* a fifth source Single
1110-
* @param o6
1135+
* @param s6
11111136
* a sixth source Single
1112-
* @param o7
1137+
* @param s7
11131138
* a seventh source Single
11141139
* @param zipFunction
11151140
* a function that, when applied to the item emitted by each of the source Singles, results in an
11161141
* item that will be emitted by the resulting Single
11171142
* @return a Single that emits the zipped results
11181143
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
11191144
*/
1120-
public final static <T1, T2, T3, T4, T5, T6, T7, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, Single<? extends T3> o3, Single<? extends T4> o4, Single<? extends T5> o5, Single<? extends T6> o6, Single<? extends T7> o7,
1121-
Func7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> zipFunction) {
1122-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3), asObservable(o4), asObservable(o5), asObservable(o6), asObservable(o7) }).lift(new OperatorZip<R>(zipFunction));
1145+
public static final <T1, T2, T3, T4, T5, T6, T7, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6, Single<? extends T7> s7,
1146+
final Func7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> zipFunction) {
1147+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4, s5, s6, s7}, new FuncN<R>() {
1148+
@Override
1149+
public R call(Object... args) {
1150+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2], (T4) args[3], (T5) args[4], (T6) args[5], (T7) args[6]);
1151+
}
1152+
});
11231153
}
11241154

11251155
/**
@@ -1132,31 +1162,36 @@ public final static <T1, T2, T3, T4, T5, T6, T7, R> Single<R> zip(Single<? exten
11321162
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
11331163
* </dl>
11341164
*
1135-
* @param o1
1165+
* @param s1
11361166
* the first source Single
1137-
* @param o2
1167+
* @param s2
11381168
* a second source Single
1139-
* @param o3
1169+
* @param s3
11401170
* a third source Single
1141-
* @param o4
1171+
* @param s4
11421172
* a fourth source Single
1143-
* @param o5
1173+
* @param s5
11441174
* a fifth source Single
1145-
* @param o6
1175+
* @param s6
11461176
* a sixth source Single
1147-
* @param o7
1177+
* @param s7
11481178
* a seventh source Single
1149-
* @param o8
1179+
* @param s8
11501180
* an eighth source Single
11511181
* @param zipFunction
11521182
* a function that, when applied to the item emitted by each of the source Singles, results in an
11531183
* item that will be emitted by the resulting Single
11541184
* @return a Single that emits the zipped results
11551185
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
11561186
*/
1157-
public final static <T1, T2, T3, T4, T5, T6, T7, T8, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, Single<? extends T3> o3, Single<? extends T4> o4, Single<? extends T5> o5, Single<? extends T6> o6, Single<? extends T7> o7, Single<? extends T8> o8,
1158-
Func8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> zipFunction) {
1159-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3), asObservable(o4), asObservable(o5), asObservable(o6), asObservable(o7), asObservable(o8) }).lift(new OperatorZip<R>(zipFunction));
1187+
public static final <T1, T2, T3, T4, T5, T6, T7, T8, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6, Single<? extends T7> s7, Single<? extends T8> s8,
1188+
final Func8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> zipFunction) {
1189+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4, s5, s6, s7, s8}, new FuncN<R>() {
1190+
@Override
1191+
public R call(Object... args) {
1192+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2], (T4) args[3], (T5) args[4], (T6) args[5], (T7) args[6], (T8) args[7]);
1193+
}
1194+
});
11601195
}
11611196

11621197
/**
@@ -1169,33 +1204,38 @@ public final static <T1, T2, T3, T4, T5, T6, T7, T8, R> Single<R> zip(Single<? e
11691204
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
11701205
* </dl>
11711206
*
1172-
* @param o1
1207+
* @param s1
11731208
* the first source Single
1174-
* @param o2
1209+
* @param s2
11751210
* a second source Single
1176-
* @param o3
1211+
* @param s3
11771212
* a third source Single
1178-
* @param o4
1213+
* @param s4
11791214
* a fourth source Single
1180-
* @param o5
1215+
* @param s5
11811216
* a fifth source Single
1182-
* @param o6
1217+
* @param s6
11831218
* a sixth source Single
1184-
* @param o7
1219+
* @param s7
11851220
* a seventh source Single
1186-
* @param o8
1221+
* @param s8
11871222
* an eighth source Single
1188-
* @param o9
1223+
* @param s9
11891224
* a ninth source Single
11901225
* @param zipFunction
11911226
* a function that, when applied to the item emitted by each of the source Singles, results in an
11921227
* item that will be emitted by the resulting Single
11931228
* @return a Single that emits the zipped results
11941229
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
11951230
*/
1196-
public final static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Single<R> zip(Single<? extends T1> o1, Single<? extends T2> o2, Single<? extends T3> o3, Single<? extends T4> o4, Single<? extends T5> o5, Single<? extends T6> o6, Single<? extends T7> o7, Single<? extends T8> o8,
1197-
Single<? extends T9> o9, Func9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> zipFunction) {
1198-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3), asObservable(o4), asObservable(o5), asObservable(o6), asObservable(o7), asObservable(o8), asObservable(o9) }).lift(new OperatorZip<R>(zipFunction));
1231+
public static final <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Single<R> zip(Single<? extends T1> s1, Single<? extends T2> s2, Single<? extends T3> s3, Single<? extends T4> s4, Single<? extends T5> s5, Single<? extends T6> s6, Single<? extends T7> s7, Single<? extends T8> s8,
1232+
Single<? extends T9> s9, final Func9<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? super T9, ? extends R> zipFunction) {
1233+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4, s5, s6, s7, s8, s9}, new FuncN<R>() {
1234+
@Override
1235+
public R call(Object... args) {
1236+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2], (T4) args[3], (T5) args[4], (T6) args[5], (T7) args[6], (T8) args[7], (T9) args[8]);
1237+
}
1238+
});
11991239
}
12001240

12011241
/**
@@ -1218,7 +1258,7 @@ public final static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Single<R> zip(Single
12181258
* @return a Single that emits the zipped results
12191259
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
12201260
*/
1221-
public static <R> Single<R> zip(Iterable<? extends Single<?>> singles, FuncN<? extends R> zipFunction) {
1261+
public static final <R> Single<R> zip(Iterable<? extends Single<?>> singles, FuncN<? extends R> zipFunction) {
12221262
return SingleOperatorZip.zip(iterableToArray(singles), zipFunction);
12231263
}
12241264

0 commit comments

Comments
 (0)