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

1.x: Observable.ignoreElementsThen #3443

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5595,6 +5595,24 @@ public final <T2, D1, D2, R> Observable<R> groupJoin(Observable<T2> right, Func1
public final Observable<T> ignoreElements() {
return lift(OperatorIgnoreElements.<T> instance());
}

/**
* Returns the source with all {@code onNext} emissions ignored concatenated with the Observable {@code following}.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/ignoreElementsThen.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code ignoreElementsThen} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return the concatenation of {@code source.ignoreElements()} with {@code following}
* @see <a href="http://reactivex.io/documentation/operators/ignoreelements.html">ReactiveX operators documentation: IgnoreElementsThen</a>
*/
@SuppressWarnings("unchecked")
@Experimental
public final <R> Observable<R> ignoreElementsThen(Observable<R> following) {
return ((Observable<R>) (Observable<?>) ignoreElements()).concatWith(following);
}

/**
* Returns an Observable that emits {@code true} if the source Observable is empty, otherwise {@code false}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,21 @@ public void onNext(Integer t) {
assertEquals(0, count.get());
}

@Test
public void testIgnoreElementsThen() {
final AtomicBoolean firstCompleted = new AtomicBoolean(false);
assertEquals(Arrays.asList(1, 2, 3),
Observable
.just("a","b","c")
.doOnCompleted(new Action0() {

@Override
public void call() {
firstCompleted.set(true);
}})
.ignoreElementsThen(Observable.just(1, 2, 3))
.toList().toBlocking().single());
assertTrue(firstCompleted.get());
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also add a test to see if the source ignored emits an error and the other is not even subscribed. I'd do this in case one decides to write an operator directly for this use case instead of using concat.

}