Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: Add Single.ignoreElement, deprecate toCompletable #5957

Merged
merged 3 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ public final Maybe<T> hide() {
/**
* Ignores the item emitted by the source Maybe and only calls {@code onComplete} or {@code onError}.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/ignoreElements.png" alt="">
* <img width="640" height="389" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.ignoreElement.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.</dd>
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -3491,9 +3491,7 @@ public final <R> R to(Function<? super Single<T>, R> convert) {
* and calls {@code onComplete} when this source {@link Single} calls
* {@code onSuccess}. Error terminal event is propagated.
* <p>
* <img width="640" height="295" src=
* "https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.toCompletable.png"
* alt="">
* <img width="640" height="436" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.toCompletable.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code toCompletable} does not operate by default on a particular {@link Scheduler}.</dd>
Expand All @@ -3503,13 +3501,36 @@ public final <R> R to(Function<? super Single<T>, R> convert) {
* calls {@code onSuccess}.
* @see <a href="http://reactivex.io/documentation/completable.html">ReactiveX documentation: Completable</a>
* @since 2.0
* @deprecated see {@link #ignoreElement()} instead, will be removed in 3.0
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
@Deprecated
public final Completable toCompletable() {
return RxJavaPlugins.onAssembly(new CompletableFromSingle<T>(this));
}

/**
* Returns a {@link Completable} that ignores the success value of this {@link Single}
* and calls {@code onComplete} instead on the returned {@code Completable}.
* <p>
* <img width="640" height="436" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.ignoreElement.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code ignoreElement} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return a {@link Completable} that calls {@code onComplete} on it's observer when the source {@link Single}
* calls {@code onSuccess}.
* @see <a href="http://reactivex.io/documentation/completable.html">ReactiveX documentation: Completable</a>
* @since 2.1.13
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Completable ignoreElement() {
return RxJavaPlugins.onAssembly(new CompletableFromSingle<T>(this));
}

/**
* Converts this Single into a {@link Flowable}.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public void timeoutOther() throws Exception {
}

@Test
@SuppressWarnings("deprecation")
public void toCompletable() {
Single.just(1)
.toCompletable()
Expand All @@ -266,6 +267,19 @@ public void toCompletable() {
.assertFailure(TestException.class);
}

@Test
public void ignoreElement() {
Single.just(1)
.ignoreElement()
.test()
.assertResult();

Single.error(new TestException())
.ignoreElement()
.test()
.assertFailure(TestException.class);
}

@Test
public void toObservable() {
Single.just(1)
Expand Down