Skip to content

Commit 06ba752

Browse files
Limit alias to Take
- as per Java 8 Stream naming conventions in discussion #678
1 parent 1e07ccc commit 06ba752

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,26 @@ public final Observable<T> lastOrDefault(T defaultValue, Func1<? super T, Boolea
41174117
return filter(predicate).takeLast(1).singleOrDefault(defaultValue);
41184118
}
41194119

4120+
/**
4121+
* Returns an Observable that emits only the first {@code num} items emitted by the source Observable.
4122+
* <p>
4123+
* Alias of {@link #take(int)} to match Java 8 Stream API naming convention.
4124+
* <p>
4125+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/take.png">
4126+
* <p>
4127+
* This method returns an Observable that will invoke a subscribing {@link Observer}'s {@link Observer#onNext onNext} function a maximum of {@code num} times before invoking
4128+
* {@link Observer#onCompleted onCompleted}.
4129+
*
4130+
* @param num
4131+
* the maximum number of items to emit
4132+
* @return an Observable that emits only the first {@code num} items emitted by the source Observable, or
4133+
* all of the items from the source Observable if that Observable emits fewer than {@code num} items
4134+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#wiki-take">RxJava Wiki: take()</a>
4135+
*/
4136+
public final Observable<T> limit(int num) {
4137+
return take(num);
4138+
}
4139+
41204140
/**
41214141
* Returns an Observable that counts the total number of items emitted by the source Observable and emits
41224142
* this count as a 64-bit Long.

0 commit comments

Comments
 (0)