|
13 | 13 |
|
14 | 14 | package io.reactivex;
|
15 | 15 |
|
16 |
| -import java.util.*; |
17 | 16 | import java.util.concurrent.*;
|
18 | 17 |
|
19 | 18 | import org.reactivestreams.*;
|
20 | 19 |
|
21 | 20 | import io.reactivex.disposables.Disposable;
|
22 | 21 | import io.reactivex.exceptions.Exceptions;
|
23 | 22 | import io.reactivex.functions.*;
|
24 |
| -import io.reactivex.internal.functions.Functions; |
25 |
| -import io.reactivex.internal.functions.Objects; |
| 23 | +import io.reactivex.internal.functions.*; |
26 | 24 | import io.reactivex.internal.operators.completable.CompletableFromSingle;
|
27 | 25 | import io.reactivex.internal.operators.flowable.*;
|
28 | 26 | import io.reactivex.internal.operators.flowable.FlowableConcatMap.ErrorMode;
|
@@ -87,12 +85,7 @@ public static <T> Single<T> amb(final Iterable<? extends SingleSource<? extends
|
87 | 85 | @SuppressWarnings("unchecked")
|
88 | 86 | public static <T> Single<T> amb(final SingleSource<? extends T>... sources) {
|
89 | 87 | if (sources.length == 0) {
|
90 |
| - return error(new Callable<Throwable>() { |
91 |
| - @Override |
92 |
| - public Throwable call() { |
93 |
| - return new NoSuchElementException(); |
94 |
| - } |
95 |
| - }); |
| 88 | + return error(SingleInternalHelper.<T>emptyThrower()); |
96 | 89 | }
|
97 | 90 | if (sources.length == 1) {
|
98 | 91 | return wrap((SingleSource<T>)sources[0]);
|
@@ -130,13 +123,7 @@ public static <T> Flowable<T> concat(Iterable<? extends SingleSource<? extends T
|
130 | 123 | */
|
131 | 124 | @SuppressWarnings({ "unchecked", "rawtypes" })
|
132 | 125 | public static <T> Flowable<T> concat(Publisher<? extends SingleSource<? extends T>> sources) {
|
133 |
| - return new FlowableConcatMap(sources, |
134 |
| - new Function<SingleSource<? extends T>, Publisher<? extends T>>() { |
135 |
| - @Override |
136 |
| - public Publisher<? extends T> apply(SingleSource<? extends T> v){ |
137 |
| - return new SingleToFlowable<T>(v); |
138 |
| - } |
139 |
| - }, 2, ErrorMode.IMMEDIATE); |
| 126 | + return new FlowableConcatMap(sources, SingleInternalHelper.toFlowable(), 2, ErrorMode.IMMEDIATE); |
140 | 127 | }
|
141 | 128 |
|
142 | 129 | /**
|
@@ -520,12 +507,7 @@ public static <T> Single<T> error(final Callable<? extends Throwable> errorSuppl
|
520 | 507 | */
|
521 | 508 | public static <T> Single<T> error(final Throwable exception) {
|
522 | 509 | Objects.requireNonNull(exception, "error is null");
|
523 |
| - return error(new Callable<Throwable>() { |
524 |
| - @Override |
525 |
| - public Throwable call() { |
526 |
| - return exception; |
527 |
| - } |
528 |
| - }); |
| 510 | + return error(Functions.justCallable(exception)); |
529 | 511 | }
|
530 | 512 |
|
531 | 513 | /**
|
@@ -740,13 +722,7 @@ public static <T> Flowable<T> merge(Iterable<? extends SingleSource<? extends T>
|
740 | 722 | */
|
741 | 723 | @SuppressWarnings({ "unchecked", "rawtypes" })
|
742 | 724 | public static <T> Flowable<T> merge(Publisher<? extends SingleSource<? extends T>> sources) {
|
743 |
| - return new FlowableFlatMap(sources, |
744 |
| - new Function<SingleSource<? extends T>, Publisher<? extends T>>() { |
745 |
| - @Override |
746 |
| - public Publisher<? extends T> apply(SingleSource<? extends T> v){ |
747 |
| - return new SingleToFlowable<T>(v); |
748 |
| - } |
749 |
| - }, false, Integer.MAX_VALUE, Flowable.bufferSize()); |
| 725 | + return new FlowableFlatMap(sources, SingleInternalHelper.toFlowable(), false, Integer.MAX_VALUE, Flowable.bufferSize()); |
750 | 726 | }
|
751 | 727 |
|
752 | 728 | /**
|
@@ -1289,31 +1265,7 @@ static <T> Single<T> wrap(SingleSource<T> source) {
|
1289 | 1265 | */
|
1290 | 1266 | public static <T, R> Single<R> zip(final Iterable<? extends SingleSource<? extends T>> sources, Function<? super Object[], ? extends R> zipper) {
|
1291 | 1267 | Objects.requireNonNull(sources, "sources is null");
|
1292 |
| - |
1293 |
| - Iterable<? extends Flowable<T>> it = new Iterable<Flowable<T>>() { |
1294 |
| - @Override |
1295 |
| - public Iterator<Flowable<T>> iterator() { |
1296 |
| - final Iterator<? extends SingleSource<? extends T>> sit = sources.iterator(); |
1297 |
| - return new Iterator<Flowable<T>>() { |
1298 |
| - |
1299 |
| - @Override |
1300 |
| - public boolean hasNext() { |
1301 |
| - return sit.hasNext(); |
1302 |
| - } |
1303 |
| - |
1304 |
| - @Override |
1305 |
| - public Flowable<T> next() { |
1306 |
| - return new SingleToFlowable<T>(sit.next()); |
1307 |
| - } |
1308 |
| - |
1309 |
| - @Override |
1310 |
| - public void remove() { |
1311 |
| - throw new UnsupportedOperationException(); |
1312 |
| - } |
1313 |
| - }; |
1314 |
| - } |
1315 |
| - }; |
1316 |
| - return Flowable.zipIterable(it, zipper, false, 1).toSingle(); |
| 1268 | + return Flowable.zipIterable(SingleInternalHelper.iterableToFlowable(sources), zipper, false, 1).toSingle(); |
1317 | 1269 | }
|
1318 | 1270 |
|
1319 | 1271 | /**
|
@@ -1826,12 +1778,7 @@ public final Single<T> cache() {
|
1826 | 1778 | */
|
1827 | 1779 | public final <U> Single<U> cast(final Class<? extends U> clazz) {
|
1828 | 1780 | Objects.requireNonNull(clazz, "clazz is null");
|
1829 |
| - return map(new Function<T, U>() { |
1830 |
| - @Override |
1831 |
| - public U apply(T v) { |
1832 |
| - return clazz.cast(v); |
1833 |
| - } |
1834 |
| - }); |
| 1781 | + return map(Functions.castFunction(clazz)); |
1835 | 1782 | }
|
1836 | 1783 |
|
1837 | 1784 | /**
|
@@ -2345,12 +2292,7 @@ public final Single<T> onErrorReturnValue(final T value) {
|
2345 | 2292 | */
|
2346 | 2293 | public final Single<T> onErrorResumeNext(final Single<? extends T> resumeSingleInCaseOfError) {
|
2347 | 2294 | Objects.requireNonNull(resumeSingleInCaseOfError, "resumeSingleInCaseOfError is null");
|
2348 |
| - return onErrorResumeNext(new Function<Throwable, Single<? extends T>>() { |
2349 |
| - @Override |
2350 |
| - public Single<? extends T> apply(Throwable t) throws Exception { |
2351 |
| - return resumeSingleInCaseOfError; |
2352 |
| - } |
2353 |
| - }); |
| 2295 | + return onErrorResumeNext(Functions.justFunction(resumeSingleInCaseOfError)); |
2354 | 2296 | }
|
2355 | 2297 |
|
2356 | 2298 | /**
|
|
0 commit comments