Skip to content

Commit 0741bb4

Browse files
Merge pull request #1787 from benjchristensen/1782-remove-withIndex
Remove *withIndex Operators
2 parents d0800c0 + cda7d34 commit 0741bb4

File tree

3 files changed

+15
-56
lines changed

3 files changed

+15
-56
lines changed

src/main/java/rx/Observable.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6924,28 +6924,6 @@ public final Observable<T> skipWhile(Func1<? super T, Boolean> predicate) {
69246924
return lift(new OperatorSkipWhile<T>(OperatorSkipWhile.toPredicate2(predicate)));
69256925
}
69266926

6927-
/**
6928-
* Returns an Observable that skips all items emitted by the source Observable as long as a specified
6929-
* condition holds true, but emits all further source items as soon as the condition becomes false.
6930-
* <p>
6931-
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/skipWhileWithIndex.png" alt="">
6932-
* <dl>
6933-
* <dt><b>Scheduler:</b></dt>
6934-
* <dd>{@code skipWhileWithIndex} does not operate by default on a particular {@link Scheduler}.</dd>
6935-
* </dl>
6936-
*
6937-
* @param predicate
6938-
* a function to test each item emitted from the source Observable. It takes the emitted item as
6939-
* the first parameter and the sequential index of the emitted item as a second parameter.
6940-
* @return an Observable that begins emitting items emitted by the source Observable when the specified
6941-
* predicate becomes false
6942-
* @see <a href="https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#skipwhile-and-skipwhilewithindex">RxJava wiki: skipWhileWithIndex</a>
6943-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211631.aspx">MSDN: Observable.SkipWhile</a>
6944-
*/
6945-
public final Observable<T> skipWhileWithIndex(Func2<? super T, Integer, Boolean> predicate) {
6946-
return lift(new OperatorSkipWhile<T>(predicate));
6947-
}
6948-
69496927
/**
69506928
* Returns an Observable that emits the items in a specified {@link Observable} before it begins to emit
69516929
* items emitted by the source Observable.
@@ -8022,30 +8000,6 @@ public final Observable<T> takeWhile(final Func1<? super T, Boolean> predicate)
80228000
return lift(new OperatorTakeWhile<T>(predicate));
80238001
}
80248002

8025-
/**
8026-
* Returns an Observable that emits the items emitted by a source Observable so long as a given predicate
8027-
* remains true, where the predicate operates on both the item and its index relative to the complete
8028-
* sequence of emitted items.
8029-
* <p>
8030-
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeWhileWithIndex.png" alt="">
8031-
* <dl>
8032-
* <dt><b>Scheduler:</b></dt>
8033-
* <dd>{@code takeWhile} does not operate by default on a particular {@link Scheduler}.</dd>
8034-
* </dl>
8035-
*
8036-
* @param predicate
8037-
* a function to test each item emitted by the source Observable for a condition; the second
8038-
* parameter of the function represents the sequential index of the source item; it returns a
8039-
* Boolean
8040-
* @return an Observable that emits items from the source Observable so long as the predicate continues to
8041-
* return {@code true} for each item, then completes
8042-
* @see <a href="https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#takewhile-and-takewhilewithindex">RxJava wiki: takeWhileWithIndex</a>
8043-
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229131.aspx">MSDN: Observable.TakeWhile</a>
8044-
*/
8045-
public final Observable<T> takeWhileWithIndex(final Func2<? super T, ? super Integer, Boolean> predicate) {
8046-
return lift(new OperatorTakeWhile<T>(predicate));
8047-
}
8048-
80498003
/**
80508004
* Returns an Observable that emits only the first item emitted by the source Observable during sequential
80518005
* time windows of a specified duration.

src/test/java/rx/internal/operators/OperatorSkipWhileTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ public Boolean call(Integer v) {
4545
}
4646
};
4747

48-
private static final Func2<Integer, Integer, Boolean> INDEX_LESS_THAN_THREE = new Func2<Integer, Integer, Boolean>() {
48+
private static final Func1<Integer, Boolean> INDEX_LESS_THAN_THREE = new Func1<Integer, Boolean>() {
49+
int index = 0;
4950
@Override
50-
public Boolean call(Integer value, Integer index) {
51-
return index < 3;
51+
public Boolean call(Integer value) {
52+
return index++ < 3;
5253
}
5354
};
5455

5556
@Test
5657
public void testSkipWithIndex() {
5758
Observable<Integer> src = Observable.just(1, 2, 3, 4, 5);
58-
src.skipWhileWithIndex(INDEX_LESS_THAN_THREE).subscribe(w);
59+
src.skipWhile(INDEX_LESS_THAN_THREE).subscribe(w);
5960

6061
InOrder inOrder = inOrder(w);
6162
inOrder.verify(w, times(1)).onNext(4);

src/test/java/rx/internal/operators/OperatorTakeWhileTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ public Boolean call(Integer input) {
8989
@Test
9090
public void testTakeWhile2() {
9191
Observable<String> w = Observable.just("one", "two", "three");
92-
Observable<String> take = w.takeWhileWithIndex(new Func2<String, Integer, Boolean>() {
92+
Observable<String> take = w.takeWhile(new Func1<String, Boolean>() {
93+
int index = 0;
94+
9395
@Override
94-
public Boolean call(String input, Integer index) {
95-
return index < 2;
96+
public Boolean call(String input) {
97+
return index++ < 2;
9698
}
9799
});
98100

@@ -158,10 +160,12 @@ public void testUnsubscribeAfterTake() {
158160

159161
@SuppressWarnings("unchecked")
160162
Observer<String> observer = mock(Observer.class);
161-
Observable<String> take = Observable.create(w).takeWhileWithIndex(new Func2<String, Integer, Boolean>() {
163+
Observable<String> take = Observable.create(w).takeWhile(new Func1<String, Boolean>() {
164+
int index = 0;
165+
162166
@Override
163-
public Boolean call(String s, Integer index) {
164-
return index < 1;
167+
public Boolean call(String s) {
168+
return index++ < 1;
165169
}
166170
});
167171
take.subscribe(observer);

0 commit comments

Comments
 (0)