Skip to content

Commit 8690235

Browse files
authored
2.x: Add Single.ignoreElement, deprecate toCompletable (#5957)
* 2.x: Add Single.ignoreElement, deprecate toCompletable * Fix javadoc method name * Have Single.ignoreElement standard from the start
1 parent eee45e0 commit 8690235

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3084,7 +3084,7 @@ public final Maybe<T> hide() {
30843084
/**
30853085
* Ignores the item emitted by the source Maybe and only calls {@code onComplete} or {@code onError}.
30863086
* <p>
3087-
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/ignoreElements.png" alt="">
3087+
* <img width="640" height="389" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.ignoreElement.png" alt="">
30883088
* <dl>
30893089
* <dt><b>Scheduler:</b></dt>
30903090
* <dd>{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.</dd>

src/main/java/io/reactivex/Single.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,9 +3491,7 @@ public final <R> R to(Function<? super Single<T>, R> convert) {
34913491
* and calls {@code onComplete} when this source {@link Single} calls
34923492
* {@code onSuccess}. Error terminal event is propagated.
34933493
* <p>
3494-
* <img width="640" height="295" src=
3495-
* "https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.toCompletable.png"
3496-
* alt="">
3494+
* <img width="640" height="436" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.toCompletable.png" alt="">
34973495
* <dl>
34983496
* <dt><b>Scheduler:</b></dt>
34993497
* <dd>{@code toCompletable} does not operate by default on a particular {@link Scheduler}.</dd>
@@ -3503,13 +3501,36 @@ public final <R> R to(Function<? super Single<T>, R> convert) {
35033501
* calls {@code onSuccess}.
35043502
* @see <a href="http://reactivex.io/documentation/completable.html">ReactiveX documentation: Completable</a>
35053503
* @since 2.0
3504+
* @deprecated see {@link #ignoreElement()} instead, will be removed in 3.0
35063505
*/
35073506
@CheckReturnValue
35083507
@SchedulerSupport(SchedulerSupport.NONE)
3508+
@Deprecated
35093509
public final Completable toCompletable() {
35103510
return RxJavaPlugins.onAssembly(new CompletableFromSingle<T>(this));
35113511
}
35123512

3513+
/**
3514+
* Returns a {@link Completable} that ignores the success value of this {@link Single}
3515+
* and calls {@code onComplete} instead on the returned {@code Completable}.
3516+
* <p>
3517+
* <img width="640" height="436" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.ignoreElement.png" alt="">
3518+
* <dl>
3519+
* <dt><b>Scheduler:</b></dt>
3520+
* <dd>{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.</dd>
3521+
* </dl>
3522+
*
3523+
* @return a {@link Completable} that calls {@code onComplete} on it's observer when the source {@link Single}
3524+
* calls {@code onSuccess}.
3525+
* @see <a href="http://reactivex.io/documentation/completable.html">ReactiveX documentation: Completable</a>
3526+
* @since 2.1.13
3527+
*/
3528+
@CheckReturnValue
3529+
@SchedulerSupport(SchedulerSupport.NONE)
3530+
public final Completable ignoreElement() {
3531+
return RxJavaPlugins.onAssembly(new CompletableFromSingle<T>(this));
3532+
}
3533+
35133534
/**
35143535
* Converts this Single into a {@link Flowable}.
35153536
* <p>

src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public void timeoutOther() throws Exception {
254254
}
255255

256256
@Test
257+
@SuppressWarnings("deprecation")
257258
public void toCompletable() {
258259
Single.just(1)
259260
.toCompletable()
@@ -266,6 +267,19 @@ public void toCompletable() {
266267
.assertFailure(TestException.class);
267268
}
268269

270+
@Test
271+
public void ignoreElement() {
272+
Single.just(1)
273+
.ignoreElement()
274+
.test()
275+
.assertResult();
276+
277+
Single.error(new TestException())
278+
.ignoreElement()
279+
.test()
280+
.assertFailure(TestException.class);
281+
}
282+
269283
@Test
270284
public void toObservable() {
271285
Single.just(1)

0 commit comments

Comments
 (0)