Skip to content

Remove *withIndex Operators #1787

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

Merged
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
46 changes: 0 additions & 46 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6924,28 +6924,6 @@ public final Observable<T> skipWhile(Func1<? super T, Boolean> predicate) {
return lift(new OperatorSkipWhile<T>(OperatorSkipWhile.toPredicate2(predicate)));
}

/**
* Returns an Observable that skips all items emitted by the source Observable as long as a specified
* condition holds true, but emits all further source items as soon as the condition becomes false.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/skipWhileWithIndex.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code skipWhileWithIndex} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param predicate
* a function to test each item emitted from the source Observable. It takes the emitted item as
* the first parameter and the sequential index of the emitted item as a second parameter.
* @return an Observable that begins emitting items emitted by the source Observable when the specified
* predicate becomes false
* @see <a href="https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#skipwhile-and-skipwhilewithindex">RxJava wiki: skipWhileWithIndex</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211631.aspx">MSDN: Observable.SkipWhile</a>
*/
public final Observable<T> skipWhileWithIndex(Func2<? super T, Integer, Boolean> predicate) {
return lift(new OperatorSkipWhile<T>(predicate));
}

/**
* Returns an Observable that emits the items in a specified {@link Observable} before it begins to emit
* items emitted by the source Observable.
Expand Down Expand Up @@ -8022,30 +8000,6 @@ public final Observable<T> takeWhile(final Func1<? super T, Boolean> predicate)
return lift(new OperatorTakeWhile<T>(predicate));
}

/**
* Returns an Observable that emits the items emitted by a source Observable so long as a given predicate
* remains true, where the predicate operates on both the item and its index relative to the complete
* sequence of emitted items.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeWhileWithIndex.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code takeWhile} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param predicate
* a function to test each item emitted by the source Observable for a condition; the second
* parameter of the function represents the sequential index of the source item; it returns a
* Boolean
* @return an Observable that emits items from the source Observable so long as the predicate continues to
* return {@code true} for each item, then completes
* @see <a href="https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#takewhile-and-takewhilewithindex">RxJava wiki: takeWhileWithIndex</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229131.aspx">MSDN: Observable.TakeWhile</a>
*/
public final Observable<T> takeWhileWithIndex(final Func2<? super T, ? super Integer, Boolean> predicate) {
return lift(new OperatorTakeWhile<T>(predicate));
}

/**
* Returns an Observable that emits only the first item emitted by the source Observable during sequential
* time windows of a specified duration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ public Boolean call(Integer v) {
}
};

private static final Func2<Integer, Integer, Boolean> INDEX_LESS_THAN_THREE = new Func2<Integer, Integer, Boolean>() {
private static final Func1<Integer, Boolean> INDEX_LESS_THAN_THREE = new Func1<Integer, Boolean>() {
int index = 0;
@Override
public Boolean call(Integer value, Integer index) {
return index < 3;
public Boolean call(Integer value) {
return index++ < 3;
}
};

@Test
public void testSkipWithIndex() {
Observable<Integer> src = Observable.just(1, 2, 3, 4, 5);
src.skipWhileWithIndex(INDEX_LESS_THAN_THREE).subscribe(w);
src.skipWhile(INDEX_LESS_THAN_THREE).subscribe(w);

InOrder inOrder = inOrder(w);
inOrder.verify(w, times(1)).onNext(4);
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/rx/internal/operators/OperatorTakeWhileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public Boolean call(Integer input) {
@Test
public void testTakeWhile2() {
Observable<String> w = Observable.just("one", "two", "three");
Observable<String> take = w.takeWhileWithIndex(new Func2<String, Integer, Boolean>() {
Observable<String> take = w.takeWhile(new Func1<String, Boolean>() {
int index = 0;

@Override
public Boolean call(String input, Integer index) {
return index < 2;
public Boolean call(String input) {
return index++ < 2;
}
});

Expand Down Expand Up @@ -158,10 +160,12 @@ public void testUnsubscribeAfterTake() {

@SuppressWarnings("unchecked")
Observer<String> observer = mock(Observer.class);
Observable<String> take = Observable.create(w).takeWhileWithIndex(new Func2<String, Integer, Boolean>() {
Observable<String> take = Observable.create(w).takeWhile(new Func1<String, Boolean>() {
int index = 0;

@Override
public Boolean call(String s, Integer index) {
return index < 1;
public Boolean call(String s) {
return index++ < 1;
}
});
take.subscribe(observer);
Expand Down