Skip to content

Commit 2dbf686

Browse files
committed
Merge pull request #3579 from artem-zinnatullin/single-zip-no-more-as-observable
1.x: No more need to convert Singles to Observables for Single.zip()
2 parents 64956e7 + b4a6fdd commit 2dbf686

File tree

2 files changed

+296
-73
lines changed

2 files changed

+296
-73
lines changed

src/main/java/rx/Single.java

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

971976
/**
@@ -978,20 +983,25 @@ public final static <T1, T2, R> Single<R> zip(Single<? extends T1> o1, Single<?
978983
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
979984
* </dl>
980985
*
981-
* @param o1
986+
* @param s1
982987
* the first source Single
983-
* @param o2
988+
* @param s2
984989
* a second source Single
985-
* @param o3
990+
* @param s3
986991
* a third source Single
987992
* @param zipFunction
988993
* a function that, when applied to the item emitted by each of the source Singles, results in an
989994
* item that will be emitted by the resulting Single
990995
* @return a Single that emits the zipped results
991996
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
992997
*/
993-
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) {
994-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3) }).lift(new OperatorZip<R>(zipFunction));
998+
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) {
999+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3}, new FuncN<R>() {
1000+
@Override
1001+
public R call(Object... args) {
1002+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2]);
1003+
}
1004+
});
9951005
}
9961006

9971007
/**
@@ -1004,22 +1014,27 @@ public final static <T1, T2, T3, R> Single<R> zip(Single<? extends T1> o1, Singl
10041014
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
10051015
* </dl>
10061016
*
1007-
* @param o1
1017+
* @param s1
10081018
* the first source Single
1009-
* @param o2
1019+
* @param s2
10101020
* a second source Single
1011-
* @param o3
1021+
* @param s3
10121022
* a third source Single
1013-
* @param o4
1023+
* @param s4
10141024
* a fourth source Single
10151025
* @param zipFunction
10161026
* a function that, when applied to the item emitted by each of the source Singles, results in an
10171027
* item that will be emitted by the resulting Single
10181028
* @return a Single that emits the zipped results
10191029
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
10201030
*/
1021-
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) {
1022-
return just(new Observable<?>[] { asObservable(o1), asObservable(o2), asObservable(o3), asObservable(o4) }).lift(new OperatorZip<R>(zipFunction));
1031+
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) {
1032+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4}, new FuncN<R>() {
1033+
@Override
1034+
public R call(Object... args) {
1035+
return zipFunction.call((T1) args[0], (T2) args[1], (T3) args[2], (T4) args[3]);
1036+
}
1037+
});
10231038
}
10241039

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

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

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

11231153
/**
@@ -1130,31 +1160,36 @@ public final static <T1, T2, T3, T4, T5, T6, T7, R> Single<R> zip(Single<? exten
11301160
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
11311161
* </dl>
11321162
*
1133-
* @param o1
1163+
* @param s1
11341164
* the first source Single
1135-
* @param o2
1165+
* @param s2
11361166
* a second source Single
1137-
* @param o3
1167+
* @param s3
11381168
* a third source Single
1139-
* @param o4
1169+
* @param s4
11401170
* a fourth source Single
1141-
* @param o5
1171+
* @param s5
11421172
* a fifth source Single
1143-
* @param o6
1173+
* @param s6
11441174
* a sixth source Single
1145-
* @param o7
1175+
* @param s7
11461176
* a seventh source Single
1147-
* @param o8
1177+
* @param s8
11481178
* an eighth source Single
11491179
* @param zipFunction
11501180
* a function that, when applied to the item emitted by each of the source Singles, results in an
11511181
* item that will be emitted by the resulting Single
11521182
* @return a Single that emits the zipped results
11531183
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
11541184
*/
1155-
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,
1156-
Func8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> zipFunction) {
1157-
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));
1185+
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,
1186+
final Func8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> zipFunction) {
1187+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4, s5, s6, s7, s8}, new FuncN<R>() {
1188+
@Override
1189+
public R call(Object... args) {
1190+
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]);
1191+
}
1192+
});
11581193
}
11591194

11601195
/**
@@ -1167,33 +1202,38 @@ public final static <T1, T2, T3, T4, T5, T6, T7, T8, R> Single<R> zip(Single<? e
11671202
* <dd>{@code zip} does not operate by default on a particular {@link Scheduler}.</dd>
11681203
* </dl>
11691204
*
1170-
* @param o1
1205+
* @param s1
11711206
* the first source Single
1172-
* @param o2
1207+
* @param s2
11731208
* a second source Single
1174-
* @param o3
1209+
* @param s3
11751210
* a third source Single
1176-
* @param o4
1211+
* @param s4
11771212
* a fourth source Single
1178-
* @param o5
1213+
* @param s5
11791214
* a fifth source Single
1180-
* @param o6
1215+
* @param s6
11811216
* a sixth source Single
1182-
* @param o7
1217+
* @param s7
11831218
* a seventh source Single
1184-
* @param o8
1219+
* @param s8
11851220
* an eighth source Single
1186-
* @param o9
1221+
* @param s9
11871222
* a ninth source Single
11881223
* @param zipFunction
11891224
* a function that, when applied to the item emitted by each of the source Singles, results in an
11901225
* item that will be emitted by the resulting Single
11911226
* @return a Single that emits the zipped results
11921227
* @see <a href="http://reactivex.io/documentation/operators/zip.html">ReactiveX operators documentation: Zip</a>
11931228
*/
1194-
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,
1195-
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) {
1196-
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));
1229+
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,
1230+
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) {
1231+
return SingleOperatorZip.zip(new Single<?>[] {s1, s2, s3, s4, s5, s6, s7, s8, s9}, new FuncN<R>() {
1232+
@Override
1233+
public R call(Object... args) {
1234+
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]);
1235+
}
1236+
});
11971237
}
11981238

11991239
/**

0 commit comments

Comments
 (0)