Skip to content

Commit f86753a

Browse files
authored
3.x: Add missing startWith overloads (#6885)
* 3.x: Add missing startWith overloads * Fix Javadocs copy-paste mistakes
1 parent c4d995d commit f86753a

File tree

10 files changed

+1141
-3
lines changed

10 files changed

+1141
-3
lines changed

src/main/java/io/reactivex/rxjava3/core/Completable.java

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,7 @@ public final Completable retryWhen(@NonNull Function<? super Flowable<Throwable>
25952595

25962596
/**
25972597
* Returns a {@code Completable} which first runs the other {@link CompletableSource}
2598-
* then this {@code Completable} if the other completed normally.
2598+
* then the current {@code Completable} if the other completed normally.
25992599
* <p>
26002600
* <img width="640" height="437" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.startWith.c.png" alt="">
26012601
* <dl>
@@ -2614,9 +2614,61 @@ public final Completable startWith(@NonNull CompletableSource other) {
26142614
return concatArray(other, this);
26152615
}
26162616

2617+
/**
2618+
* Returns a {@link Flowable} which first runs the other {@link SingleSource}
2619+
* then the current {@code Completable} if the other succeeded normally.
2620+
* <p>
2621+
* <img width="640" height="388" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.startWith.s.png" alt="">
2622+
* <dl>
2623+
* <dt><b>Backpressure:</b></dt>
2624+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
2625+
* <dt><b>Scheduler:</b></dt>
2626+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
2627+
* </dl>
2628+
* @param <T> the element type of the {@code other} {@code SingleSource}.
2629+
* @param other the other {@code SingleSource} to run first
2630+
* @return the new {@code Flowable} instance
2631+
* @throws NullPointerException if {@code other} is {@code null}
2632+
* @since 3.0.0
2633+
*/
2634+
@CheckReturnValue
2635+
@NonNull
2636+
@SchedulerSupport(SchedulerSupport.NONE)
2637+
@BackpressureSupport(BackpressureKind.FULL)
2638+
public final <T> Flowable<T> startWith(@NonNull SingleSource<T> other) {
2639+
Objects.requireNonNull(other, "other is null");
2640+
return Flowable.concat(Single.wrap(other).toFlowable(), toFlowable());
2641+
}
2642+
2643+
/**
2644+
* Returns a {@link Flowable} which first runs the other {@link MaybeSource}
2645+
* then the current {@code Completable} if the other succeeded or completed normally.
2646+
* <p>
2647+
* <img width="640" height="266" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.startWith.m.png" alt="">
2648+
* <dl>
2649+
* <dt><b>Backpressure:</b></dt>
2650+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
2651+
* <dt><b>Scheduler:</b></dt>
2652+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
2653+
* </dl>
2654+
* @param <T> the element type of the {@code other} {@code MaybeSource}.
2655+
* @param other the other {@code MaybeSource} to run first
2656+
* @return the new {@code Flowable} instance
2657+
* @throws NullPointerException if {@code other} is {@code null}
2658+
* @since 3.0.0
2659+
*/
2660+
@CheckReturnValue
2661+
@NonNull
2662+
@SchedulerSupport(SchedulerSupport.NONE)
2663+
@BackpressureSupport(BackpressureKind.FULL)
2664+
public final <T> Flowable<T> startWith(@NonNull MaybeSource<T> other) {
2665+
Objects.requireNonNull(other, "other is null");
2666+
return Flowable.concat(Maybe.wrap(other).toFlowable(), toFlowable());
2667+
}
2668+
26172669
/**
26182670
* Returns an {@link Observable} which first delivers the events
2619-
* of the other {@link ObservableSource} then runs this {@code Completable}.
2671+
* of the other {@link ObservableSource} then runs the current {@code Completable}.
26202672
* <p>
26212673
* <img width="640" height="289" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.startWith.o.png" alt="">
26222674
* <dl>
@@ -2635,9 +2687,10 @@ public final <T> Observable<T> startWith(@NonNull ObservableSource<T> other) {
26352687
Objects.requireNonNull(other, "other is null");
26362688
return Observable.wrap(other).concatWith(this.toObservable());
26372689
}
2690+
26382691
/**
26392692
* Returns a {@link Flowable} which first delivers the events
2640-
* of the other {@link Publisher} then runs this {@code Completable}.
2693+
* of the other {@link Publisher} then runs the current {@code Completable}.
26412694
* <p>
26422695
* <img width="640" height="250" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.startWith.p.png" alt="">
26432696
* <dl>

src/main/java/io/reactivex/rxjava3/core/Flowable.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15238,6 +15238,81 @@ public final Flowable<T> startWithIterable(@NonNull Iterable<@NonNull ? extends
1523815238
return concatArray(fromIterable(items), this);
1523915239
}
1524015240

15241+
/**
15242+
* Returns a {@code Flowable} which first runs the other {@link CompletableSource}
15243+
* then the current {@code Flowable} if the other completed normally.
15244+
* <p>
15245+
* <img width="640" height="268" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Flowable.startWith.c.png" alt="">
15246+
* <dl>
15247+
* <dt><b>Backpressure:</b></dt>
15248+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
15249+
* <dt><b>Scheduler:</b></dt>
15250+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
15251+
* </dl>
15252+
* @param other the other {@code CompletableSource} to run first
15253+
* @return the new {@code Flowable} instance
15254+
* @throws NullPointerException if {@code other} is {@code null}
15255+
* @since 3.0.0
15256+
*/
15257+
@CheckReturnValue
15258+
@NonNull
15259+
@SchedulerSupport(SchedulerSupport.NONE)
15260+
@BackpressureSupport(BackpressureKind.FULL)
15261+
public final Flowable<T> startWith(@NonNull CompletableSource other) {
15262+
Objects.requireNonNull(other, "other is null");
15263+
return Flowable.concat(Completable.wrap(other).<T>toFlowable(), this);
15264+
}
15265+
15266+
/**
15267+
* Returns a {@code Flowable} which first runs the other {@link SingleSource}
15268+
* then the current {@code Flowable} if the other succeeded normally.
15269+
* <p>
15270+
* <img width="640" height="248" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Flowable.startWith.s.png" alt="">
15271+
* <dl>
15272+
* <dt><b>Backpressure:</b></dt>
15273+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
15274+
* <dt><b>Scheduler:</b></dt>
15275+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
15276+
* </dl>
15277+
* @param other the other {@code SingleSource} to run first
15278+
* @return the new {@code Flowable} instance
15279+
* @throws NullPointerException if {@code other} is {@code null}
15280+
* @since 3.0.0
15281+
*/
15282+
@CheckReturnValue
15283+
@NonNull
15284+
@SchedulerSupport(SchedulerSupport.NONE)
15285+
@BackpressureSupport(BackpressureKind.FULL)
15286+
public final Flowable<T> startWith(@NonNull SingleSource<T> other) {
15287+
Objects.requireNonNull(other, "other is null");
15288+
return Flowable.concat(Single.wrap(other).toFlowable(), this);
15289+
}
15290+
15291+
/**
15292+
* Returns a {@code Flowable} which first runs the other {@link MaybeSource}
15293+
* then the current {@code Flowable} if the other succeeded or completed normally.
15294+
* <p>
15295+
* <img width="640" height="168" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Flowable.startWith.m.png" alt="">
15296+
* <dl>
15297+
* <dt><b>Backpressure:</b></dt>
15298+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
15299+
* <dt><b>Scheduler:</b></dt>
15300+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
15301+
* </dl>
15302+
* @param other the other {@code MaybeSource} to run first
15303+
* @return the new {@code Flowable} instance
15304+
* @throws NullPointerException if {@code other} is {@code null}
15305+
* @since 3.0.0
15306+
*/
15307+
@CheckReturnValue
15308+
@NonNull
15309+
@SchedulerSupport(SchedulerSupport.NONE)
15310+
@BackpressureSupport(BackpressureKind.FULL)
15311+
public final Flowable<T> startWith(@NonNull MaybeSource<T> other) {
15312+
Objects.requireNonNull(other, "other is null");
15313+
return Flowable.concat(Maybe.wrap(other).toFlowable(), this);
15314+
}
15315+
1524115316
/**
1524215317
* Returns a {@code Flowable} that emits the items in a specified {@link Publisher} before it begins to emit
1524315318
* items emitted by the current {@code Flowable}.

src/main/java/io/reactivex/rxjava3/core/Maybe.java

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.reactivestreams.*;
2121

2222
import io.reactivex.rxjava3.annotations.*;
23+
import io.reactivex.rxjava3.core.Observable;
2324
import io.reactivex.rxjava3.disposables.Disposable;
2425
import io.reactivex.rxjava3.exceptions.*;
2526
import io.reactivex.rxjava3.functions.*;
@@ -4859,6 +4860,129 @@ public final Maybe<T> retryWhen(
48594860
return toFlowable().retryWhen(handler).singleElement();
48604861
}
48614862

4863+
/**
4864+
* Returns a {@link Flowable} which first runs the other {@link CompletableSource}
4865+
* then the current {@code Maybe} if the other completed normally.
4866+
* <p>
4867+
* <img width="640" height="268" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.startWith.c.png" alt="">
4868+
* <dl>
4869+
* <dt><b>Backpressure:</b></dt>
4870+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
4871+
* <dt><b>Scheduler:</b></dt>
4872+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
4873+
* </dl>
4874+
* @param other the other {@code CompletableSource} to run first
4875+
* @return the new {@code Flowable} instance
4876+
* @throws NullPointerException if {@code other} is {@code null}
4877+
* @since 3.0.0
4878+
*/
4879+
@CheckReturnValue
4880+
@NonNull
4881+
@SchedulerSupport(SchedulerSupport.NONE)
4882+
@BackpressureSupport(BackpressureKind.FULL)
4883+
public final Flowable<T> startWith(@NonNull CompletableSource other) {
4884+
Objects.requireNonNull(other, "other is null");
4885+
return Flowable.concat(Completable.wrap(other).<T>toFlowable(), toFlowable());
4886+
}
4887+
4888+
/**
4889+
* Returns a {@link Flowable} which first runs the other {@link SingleSource}
4890+
* then the current {@code Maybe} if the other succeeded normally.
4891+
* <p>
4892+
* <img width="640" height="237" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.startWith.s.png" alt="">
4893+
* <dl>
4894+
* <dt><b>Backpressure:</b></dt>
4895+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
4896+
* <dt><b>Scheduler:</b></dt>
4897+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
4898+
* </dl>
4899+
* @param other the other {@code SingleSource} to run first
4900+
* @return the new {@code Flowable} instance
4901+
* @throws NullPointerException if {@code other} is {@code null}
4902+
* @since 3.0.0
4903+
*/
4904+
@CheckReturnValue
4905+
@NonNull
4906+
@SchedulerSupport(SchedulerSupport.NONE)
4907+
@BackpressureSupport(BackpressureKind.FULL)
4908+
public final Flowable<T> startWith(@NonNull SingleSource<T> other) {
4909+
Objects.requireNonNull(other, "other is null");
4910+
return Flowable.concat(Single.wrap(other).toFlowable(), toFlowable());
4911+
}
4912+
4913+
/**
4914+
* Returns a {@link Flowable} which first runs the other {@link MaybeSource}
4915+
* then the current {@code Maybe} if the other succeeded or completed normally.
4916+
* <p>
4917+
* <img width="640" height="178" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.startWith.m.png" alt="">
4918+
* <dl>
4919+
* <dt><b>Backpressure:</b></dt>
4920+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
4921+
* <dt><b>Scheduler:</b></dt>
4922+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
4923+
* </dl>
4924+
* @param other the other {@code MaybeSource} to run first
4925+
* @return the new {@code Flowable} instance
4926+
* @throws NullPointerException if {@code other} is {@code null}
4927+
* @since 3.0.0
4928+
*/
4929+
@CheckReturnValue
4930+
@NonNull
4931+
@SchedulerSupport(SchedulerSupport.NONE)
4932+
@BackpressureSupport(BackpressureKind.FULL)
4933+
public final Flowable<T> startWith(@NonNull MaybeSource<T> other) {
4934+
Objects.requireNonNull(other, "other is null");
4935+
return Flowable.concat(Maybe.wrap(other).toFlowable(), toFlowable());
4936+
}
4937+
4938+
/**
4939+
* Returns an {@link Observable} which first delivers the events
4940+
* of the other {@link ObservableSource} then runs the current {@code Maybe}.
4941+
* <p>
4942+
* <img width="640" height="179" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.startWith.o.png" alt="">
4943+
* <dl>
4944+
* <dt><b>Scheduler:</b></dt>
4945+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
4946+
* </dl>
4947+
* @param other the other {@code ObservableSource} to run first
4948+
* @return the new {@code Observable} instance
4949+
* @throws NullPointerException if {@code other} is {@code null}
4950+
* @since 3.0.0
4951+
*/
4952+
@CheckReturnValue
4953+
@NonNull
4954+
@SchedulerSupport(SchedulerSupport.NONE)
4955+
public final Observable<T> startWith(@NonNull ObservableSource<T> other) {
4956+
Objects.requireNonNull(other, "other is null");
4957+
return Observable.wrap(other).concatWith(this.toObservable());
4958+
}
4959+
4960+
/**
4961+
* Returns a {@link Flowable} which first delivers the events
4962+
* of the other {@link Publisher} then runs the current {@code Maybe}.
4963+
* <p>
4964+
* <img width="640" height="179" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.startWith.p.png" alt="">
4965+
* <dl>
4966+
* <dt><b>Backpressure:</b></dt>
4967+
* <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer
4968+
* and expects the other {@code Publisher} to honor it as well.</dd>
4969+
* <dt><b>Scheduler:</b></dt>
4970+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
4971+
* </dl>
4972+
* @param other the other {@code Publisher} to run first
4973+
* @return the new {@code Flowable} instance
4974+
* @throws NullPointerException if {@code other} is {@code null}
4975+
* @since 3.0.0
4976+
*/
4977+
@CheckReturnValue
4978+
@NonNull
4979+
@BackpressureSupport(BackpressureKind.FULL)
4980+
@SchedulerSupport(SchedulerSupport.NONE)
4981+
public final Flowable<T> startWith(@NonNull Publisher<T> other) {
4982+
Objects.requireNonNull(other, "other is null");
4983+
return toFlowable().startWith(other);
4984+
}
4985+
48624986
/**
48634987
* Subscribes to a {@code Maybe} and ignores {@code onSuccess} and {@code onComplete} emissions.
48644988
* <p>

src/main/java/io/reactivex/rxjava3/core/Observable.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12704,6 +12704,72 @@ public final Observable<T> startWithIterable(@NonNull Iterable<@NonNull ? extend
1270412704
return concatArray(fromIterable(items), this);
1270512705
}
1270612706

12707+
/**
12708+
* Returns an {@code Observable} which first runs the other {@link CompletableSource}
12709+
* then the current {@code Observable} if the other completed normally.
12710+
* <p>
12711+
* <img width="640" height="437" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Observable.startWith.c.png" alt="">
12712+
* <dl>
12713+
* <dt><b>Scheduler:</b></dt>
12714+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
12715+
* </dl>
12716+
* @param other the other {@code CompletableSource} to run first
12717+
* @return the new {@code Observable} instance
12718+
* @throws NullPointerException if {@code other} is {@code null}
12719+
* @since 3.0.0
12720+
*/
12721+
@CheckReturnValue
12722+
@NonNull
12723+
@SchedulerSupport(SchedulerSupport.NONE)
12724+
public final Observable<T> startWith(@NonNull CompletableSource other) {
12725+
Objects.requireNonNull(other, "other is null");
12726+
return Observable.concat(Completable.wrap(other).<T>toObservable(), this);
12727+
}
12728+
12729+
/**
12730+
* Returns an {@code Observable} which first runs the other {@link SingleSource}
12731+
* then the current {@code Observable} if the other succeeded normally.
12732+
* <p>
12733+
* <img width="640" height="248" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Observable.startWith.s.png" alt="">
12734+
* <dl>
12735+
* <dt><b>Scheduler:</b></dt>
12736+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
12737+
* </dl>
12738+
* @param other the other {@code SingleSource} to run first
12739+
* @return the new {@code Observable} instance
12740+
* @throws NullPointerException if {@code other} is {@code null}
12741+
* @since 3.0.0
12742+
*/
12743+
@CheckReturnValue
12744+
@NonNull
12745+
@SchedulerSupport(SchedulerSupport.NONE)
12746+
public final Observable<T> startWith(@NonNull SingleSource<T> other) {
12747+
Objects.requireNonNull(other, "other is null");
12748+
return Observable.concat(Single.wrap(other).toObservable(), this);
12749+
}
12750+
12751+
/**
12752+
* Returns an {@code Observable} which first runs the other {@link MaybeSource}
12753+
* then the current {@code Observable} if the other succeeded or completed normally.
12754+
* <p>
12755+
* <img width="640" height="168" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Observable.startWith.m.png" alt="">
12756+
* <dl>
12757+
* <dt><b>Scheduler:</b></dt>
12758+
* <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
12759+
* </dl>
12760+
* @param other the other {@code MaybeSource} to run first
12761+
* @return the new {@code Observable} instance
12762+
* @throws NullPointerException if {@code other} is {@code null}
12763+
* @since 3.0.0
12764+
*/
12765+
@CheckReturnValue
12766+
@NonNull
12767+
@SchedulerSupport(SchedulerSupport.NONE)
12768+
public final Observable<T> startWith(@NonNull MaybeSource<T> other) {
12769+
Objects.requireNonNull(other, "other is null");
12770+
return Observable.concat(Maybe.wrap(other).toObservable(), this);
12771+
}
12772+
1270712773
/**
1270812774
* Returns an {@code Observable} that emits the items in a specified {@link ObservableSource} before it begins to emit
1270912775
* items emitted by the current {@code Observable}.

0 commit comments

Comments
 (0)