Skip to content

Commit 3d1b379

Browse files
vanniktechakarnokd
authored andcommitted
2.x: Remove takeFirst(predicate) in Observable & Flowable (#4595)
1 parent 4f86ee0 commit 3d1b379

File tree

6 files changed

+6
-63
lines changed

6 files changed

+6
-63
lines changed

src/main/java/io/reactivex/Flowable.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12341,32 +12341,6 @@ public final Flowable<T> take(long time, TimeUnit unit, Scheduler scheduler) {
1234112341
return takeUntil(timer(time, unit, scheduler));
1234212342
}
1234312343

12344-
/**
12345-
* Returns a Flowable that emits only the very first item emitted by the source Publisher that satisfies
12346-
* a specified condition.
12347-
* <p>
12348-
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeFirstN.png" alt="">
12349-
* <dl>
12350-
* <dt><b>Backpressure:</b></dt>
12351-
* <dd>The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s backpressure
12352-
* behavior.</dd>
12353-
* <dt><b>Scheduler:</b></dt>
12354-
* <dd>{@code takeFirst} does not operate by default on a particular {@link Scheduler}.</dd>
12355-
* </dl>
12356-
*
12357-
* @param predicate
12358-
* the condition any item emitted by the source Publisher has to satisfy
12359-
* @return a Flowable that emits only the very first item emitted by the source Publisher that satisfies
12360-
* the given condition, or that completes without emitting anything if the source Publisher
12361-
* completes without emitting a single condition-satisfying item
12362-
* @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
12363-
*/
12364-
@BackpressureSupport(BackpressureKind.SPECIAL) // may trigger UNBOUNDED_IN
12365-
@SchedulerSupport(SchedulerSupport.NONE)
12366-
public final Flowable<T> takeFirst(Predicate<? super T> predicate) {
12367-
return filter(predicate).take(1);
12368-
}
12369-
1237012344
/**
1237112345
* Returns a Flowable that emits at most the last {@code count} items emitted by the source Publisher. If the source emits fewer than
1237212346
* {@code count} items then all of its items are emitted.

src/main/java/io/reactivex/Observable.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10333,28 +10333,6 @@ public final Observable<T> take(long time, TimeUnit unit, Scheduler scheduler) {
1033310333
return takeUntil(timer(time, unit, scheduler));
1033410334
}
1033510335

10336-
/**
10337-
* Returns an Observable that emits only the very first item emitted by the source ObservableSource that satisfies
10338-
* a specified condition.
10339-
* <p>
10340-
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/takeFirstN.png" alt="">
10341-
* <dl>
10342-
* <dt><b>Scheduler:</b></dt>
10343-
* <dd>{@code takeFirst} does not operate by default on a particular {@link Scheduler}.</dd>
10344-
* </dl>
10345-
*
10346-
* @param predicate
10347-
* the condition any item emitted by the source ObservableSource has to satisfy
10348-
* @return an Observable that emits only the very first item emitted by the source ObservableSource that satisfies
10349-
* the given condition, or that completes without emitting anything if the source ObservableSource
10350-
* completes without emitting a single condition-satisfying item
10351-
* @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
10352-
*/
10353-
@SchedulerSupport(SchedulerSupport.NONE)
10354-
public final Observable<T> takeFirst(Predicate<? super T> predicate) {
10355-
return filter(predicate).take(1);
10356-
}
10357-
1035810336
/**
1035910337
* Returns an Observable that emits at most the last {@code count} items emitted by the source ObservableSource. If the source emits fewer than
1036010338
* {@code count} items then all of its items are emitted.

src/test/java/io/reactivex/flowable/FlowableNullTests.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,11 +2179,6 @@ public void takeTimedSchedulerNull() {
21792179
just1.take(1, TimeUnit.SECONDS, null);
21802180
}
21812181

2182-
@Test(expected = NullPointerException.class)
2183-
public void takeFirstNull() {
2184-
just1.takeFirst(null);
2185-
}
2186-
21872182
@Test(expected = NullPointerException.class)
21882183
public void takeLastTimedUnitNull() {
21892184
just1.takeLast(1, null, Schedulers.single());
@@ -2957,4 +2952,4 @@ public Object apply(Object[] v) {
29572952
}
29582953
}, 128, just1).blockingLast();
29592954
}
2960-
}
2955+
}

src/test/java/io/reactivex/flowable/FlowableTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ public Throwable call() {
182182
verify(wo, times(1)).onError(any(RuntimeException.class));
183183
}
184184

185+
@Test
185186
public void testTakeFirstWithPredicateOfSome() {
186187
Flowable<Integer> observable = Flowable.just(1, 3, 5, 4, 6, 3);
187-
observable.takeFirst(IS_EVEN).subscribe(w);
188+
observable.filter(IS_EVEN).take(1).subscribe(w);
188189
verify(w, times(1)).onNext(anyInt());
189190
verify(w).onNext(4);
190191
verify(w, times(1)).onComplete();
@@ -194,7 +195,7 @@ public void testTakeFirstWithPredicateOfSome() {
194195
@Test
195196
public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() {
196197
Flowable<Integer> observable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1);
197-
observable.takeFirst(IS_EVEN).subscribe(w);
198+
observable.filter(IS_EVEN).take(1).subscribe(w);
198199
verify(w, never()).onNext(anyInt());
199200
verify(w, times(1)).onComplete();
200201
verify(w, never()).onError(any(Throwable.class));

src/test/java/io/reactivex/observable/ObservableNullTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,11 +2250,6 @@ public void takeTimedSchedulerNull() {
22502250
just1.take(1, TimeUnit.SECONDS, null);
22512251
}
22522252

2253-
@Test(expected = NullPointerException.class)
2254-
public void takeFirstNull() {
2255-
just1.takeFirst(null);
2256-
}
2257-
22582253
@Test(expected = NullPointerException.class)
22592254
public void takeLastTimedUnitNull() {
22602255
just1.takeLast(1, null, Schedulers.single());

src/test/java/io/reactivex/observable/ObservableTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public Throwable call() {
186186
@Test
187187
public void testTakeFirstWithPredicateOfSome() {
188188
Observable<Integer> o = Observable.just(1, 3, 5, 4, 6, 3);
189-
o.takeFirst(IS_EVEN).subscribe(w);
189+
o.filter(IS_EVEN).take(1).subscribe(w);
190190
verify(w, times(1)).onNext(anyInt());
191191
verify(w).onNext(4);
192192
verify(w, times(1)).onComplete();
@@ -196,7 +196,7 @@ public void testTakeFirstWithPredicateOfSome() {
196196
@Test
197197
public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() {
198198
Observable<Integer> o = Observable.just(1, 3, 5, 7, 9, 7, 5, 3, 1);
199-
o.takeFirst(IS_EVEN).subscribe(w);
199+
o.filter(IS_EVEN).take(1).subscribe(w);
200200
verify(w, never()).onNext(anyInt());
201201
verify(w, times(1)).onComplete();
202202
verify(w, never()).onError(any(Throwable.class));

0 commit comments

Comments
 (0)