/** * Returns an Observable that emits the item emitted by the source Single, then the item emitted by the * specified Single. * <p> * <img width="640" height="335" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.concatWith.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concatWith} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param other * a Single to be concatenated after the current * @return an Observable that emits the item emitted by the source Single, followed by the item emitted by * {@code t1} * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable<T> concatWith(SingleSource<? extends T> other) { return concat(this, other); }
/** * Returns an Observable that emits the item emitted by the source Single, then the item emitted by the * specified Single. * <p> * <img width="640" height="335" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.concatWith.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concatWith} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param other * a Single to be concatenated after the current * @return an Observable that emits the item emitted by the source Single, followed by the item emitted by * {@code t1} * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final Observable<T> concatWith(SingleSource<? extends T> other) { return concat(this, other); }
@Test(expected = NullPointerException.class) public void concatObservableNull() { Single.concat((Observable<Single<Integer>>)null); }
@Test(expected = NullPointerException.class) public void concatIterableNull() { Single.concat((Iterable<Single<Integer>>)null); }
/** * Concatenate the single values, in a non-overlapping fashion, of the Single sources provided by * an Iterable sequence. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param <T> the value type * @param sources the Iterable sequence of SingleSource instances * @return the new Observable instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static <T> Observable<T> concat(Iterable<? extends SingleSource<? extends T>> sources) { return concat(Observable.fromIterable(sources)); }
/** * Concatenate the single values, in a non-overlapping fashion, of the Single sources provided by * an Iterable sequence. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param <T> the value type * @param sources the Iterable sequence of SingleSource instances * @return the new Observable instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static <T> Observable<T> concat(Iterable<? extends SingleSource<? extends T>> sources) { return concat(Observable.fromIterable(sources)); }
@SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void concatIterableOneIsNull() { Single.concat(Arrays.asList(just1, null)).blockingSubscribe(); }
@Test(expected = NullPointerException.class) public void concatIterableIteratorNull() { Single.concat(new Iterable<Single<Object>>() { @Override public Iterator<Single<Object>> iterator() { return null; } }).blockingSubscribe(); }
/** * Returns an Observable that emits the items emitted by two Singles, one after the other. * <p> * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.concat.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param <T> the common value type * @param source1 * a Single to be concatenated * @param source2 * a Single to be concatenated * @return an Observable that emits items emitted by the two source Singles, one after the other. * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static <T> Observable<T> concat( SingleSource<? extends T> source1, SingleSource<? extends T> source2 ) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return concat(Observable.fromArray(source1, source2)); }
/** * Returns an Observable that emits the items emitted by two Singles, one after the other. * <p> * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.concat.png" alt=""> * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param <T> the common value type * @param source1 * a Single to be concatenated * @param source2 * a Single to be concatenated * @return an Observable that emits items emitted by the two source Singles, one after the other. * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static <T> Observable<T> concat( SingleSource<? extends T> source1, SingleSource<? extends T> source2 ) { ObjectHelper.requireNonNull(source1, "source1 is null"); ObjectHelper.requireNonNull(source2, "source2 is null"); return concat(Observable.fromArray(source1, source2)); }
@Test public void callable() { Single.concat(Observable.fromCallable(new Callable<Single<Integer>>() { @Override public Single<Integer> call() throws Exception { return Single.just(1); } })) .test() .assertResult(1); } }
ObjectHelper.requireNonNull(source2, "source2 is null"); ObjectHelper.requireNonNull(source3, "source3 is null"); return concat(Observable.fromArray(source1, source2, source3));
ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return concat(Observable.fromArray(source1, source2, source3, source4));
ObjectHelper.requireNonNull(source3, "source3 is null"); ObjectHelper.requireNonNull(source4, "source4 is null"); return concat(Observable.fromArray(source1, source2, source3, source4));
@Test public void scalar() { Single.concat(Observable.just(Single.just(1))) .test() .assertResult(1); }
@Test public void concat2() { Single.concat(Single.just(1), Single.just(2)) .test() .assertResult(1, 2); }
@SuppressWarnings("unchecked") @Test public void noSubsequentSubscriptionIterable() { final int[] calls = { 0 }; Single<Integer> source = Single.create(new SingleOnSubscribe<Integer>() { @Override public void subscribe(SingleEmitter<Integer> s) throws Exception { calls[0]++; s.onSuccess(1); } }); Single.concat(Arrays.asList(source, source)).firstElement() .test() .assertResult(1); assertEquals(1, calls[0]); } }
@Test public void concat3() { Single.concat(Single.just(1), Single.just(2), Single.just(3)) .test() .assertResult(1, 2, 3); }
@SuppressWarnings("unchecked") @Test public void concatObservable() { for (int i = 1; i < 100; i++) { Single<Integer>[] array = new Single[i]; Arrays.fill(array, Single.just(1)); Single.concat(Observable.fromArray(array)) .test() .assertSubscribed() .assertValueCount(i) .assertNoErrors() .assertComplete(); } }
@Test public void concat4() { Single.concat(Single.just(1), Single.just(2), Single.just(3), Single.just(4)) .test() .assertResult(1, 2, 3, 4); }