Observable { @NonNull public static <T> Observable<T> concat(@NonNull final Observable<T> lh, @NonNull final Observable<T> rh) { final CompoundSubscription compoundSubscription = new CompoundSubscription(); return create(new Function<Observer<T>, Subscription>() { @NonNull @Override public Subscription apply(@NonNull final Observer<T> observer) { compoundSubscription.add(lh.subscribe(new Observer<T>() { @Override public void onNext(@NonNull T value) { observer.onNext(value); } @Override public void onCompleted() { compoundSubscription.add(rh.subscribe(observer)); } @Override public void onError(@NonNull Exception e) { observer.onError(e); } })); return Subscription.create(new Runnable() { @Override public void run() { compoundSubscription.cancel(); } }); } }); } protected  Observable(); protected  Observable(@Nullable Function<Observer<T>, Subscription> onSubscribe); @NonNull static Observable<T> create(@NonNull Function<Observer<T>, Subscription> func); @NonNull static Observable<T> just(@NonNull final T value); @NonNull static Observable<T> empty(); @NonNull static Observable<T> never(); @NonNull static Observable<T> error(@NonNull final Exception e); @NonNull static Observable<T> from(@NonNull final Collection<T> collection); @NonNull Subscription subscribe(@NonNull Observer<T> observer); @NonNull Observable<R> flatMap(@NonNull final Function<T, Observable<R>> func); @NonNull Observable<R> map(@NonNull final Function<T, R> func); @NonNull Observable<T> filter(@NonNull final Predicate<T> pred); @NonNull Observable<T> distinctUntilChanged(); @NonNull Observable<T> defaultIfEmpty(@NonNull final T defaultValue); @NonNull Observable<T> observeOn(@NonNull final Scheduler scheduler); @NonNull Observable<T> subscribeOn(@NonNull final Scheduler scheduler); @NonNull static Observable<T> merge(@NonNull final Observable<T> lh, @NonNull final Observable<T> rh); @NonNull static Observable<T> merge(@NonNull Collection<Observable<T>> observables); @NonNull static Observable<T> concat(@NonNull final Observable<T> lh, @NonNull final Observable<T> rh); @NonNull static Observable<T> defer(@NonNull final Supplier<Observable<T>> func); @NonNull static Observable<R> zip(@NonNull final Observable<T> lh, @NonNull final Observable<T> rh, @NonNull final BiFunction<T, T, R> func);  }
@Test public void testConcat() throws Exception { Subject<Integer> first = Subject.create(); Subject<Integer> second = Subject.create(); Observable<Integer> merged = Observable.concat(first, second); subscribeObservable(merged); first.onNext(1); second.onNext(4); first.onNext(2); second.onNext(5); first.onNext(3); second.onNext(6); first.onCompleted(); second.onNext(7); second.onNext(8); second.onNext(9); second.onCompleted(); performAsserts(null, null, Arrays.asList(1, 2, 3, 7, 8, 9), 6, 1, 0); }