Skip to content

Commit e50aa5d

Browse files
Merge pull request #1232 from benjchristensen/678-Java8-names
Adopt Limit and ForEach Java 8 Naming Conventions
2 parents 1e07ccc + 48a845c commit e50aa5d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,69 @@ public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? e
39023902
return mergeMap(func);
39033903
}
39043904

3905+
/**
3906+
* Subscribes to the {@link Observable} and receives notifications for each element.
3907+
* <p>
3908+
* Alias to {@link #subscribe(Action1)}
3909+
*
3910+
* @param onNext
3911+
* {@link Action1} to execute for each item.
3912+
* @throws IllegalArgumentException
3913+
* if {@code onNext} is null
3914+
* @throws IllegalArgumentException
3915+
* if {@code onError} is null
3916+
* @throws IllegalArgumentException
3917+
* if {@code onComplete} is null
3918+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable#wiki-onnext-oncompleted-and-onerror">RxJava Wiki: onNext, onCompleted, and onError</a>
3919+
* */
3920+
public final void forEach(final Action1<? super T> onNext) {
3921+
subscribe(onNext);
3922+
}
3923+
3924+
/**
3925+
* Subscribes to the {@link Observable} and receives notifications for each element and error events.
3926+
* <p>
3927+
* Alias to {@link #subscribe(Action1, Action1)}
3928+
*
3929+
* @param onNext
3930+
* {@link Action1} to execute for each item.
3931+
* @param onError
3932+
* {@link Action1} to execute when an error is emitted.
3933+
* @throws IllegalArgumentException
3934+
* if {@code onNext} is null
3935+
* @throws IllegalArgumentException
3936+
* if {@code onError} is null
3937+
* @throws IllegalArgumentException
3938+
* if {@code onComplete} is null
3939+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable#wiki-onnext-oncompleted-and-onerror">RxJava Wiki: onNext, onCompleted, and onError</a>
3940+
* */
3941+
public final void forEach(final Action1<? super T> onNext, final Action1<Throwable> onError) {
3942+
subscribe(onNext, onError);
3943+
}
3944+
3945+
/**
3946+
* Subscribes to the {@link Observable} and receives notifications for each element and the terminal events.
3947+
* <p>
3948+
* Alias to {@link #subscribe(Action1, Action1, Action0)}
3949+
*
3950+
* @param onNext
3951+
* {@link Action1} to execute for each item.
3952+
* @param onError
3953+
* {@link Action1} to execute when an error is emitted.
3954+
* @param onComplete
3955+
* {@link Action0} to execute when completion is signalled.
3956+
* @throws IllegalArgumentException
3957+
* if {@code onNext} is null
3958+
* @throws IllegalArgumentException
3959+
* if {@code onError} is null
3960+
* @throws IllegalArgumentException
3961+
* if {@code onComplete} is null
3962+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable#wiki-onnext-oncompleted-and-onerror">RxJava Wiki: onNext, onCompleted, and onError</a>
3963+
* */
3964+
public final void forEach(final Action1<? super T> onNext, final Action1<Throwable> onError, final Action0 onComplete) {
3965+
subscribe(onNext, onError, onComplete);
3966+
}
3967+
39053968
/**
39063969
* Groups the items emitted by an Observable according to a specified criterion, and emits these grouped
39073970
* items as {@link GroupedObservable}s, one {@code GroupedObservable} per group.
@@ -4117,6 +4180,26 @@ public final Observable<T> lastOrDefault(T defaultValue, Func1<? super T, Boolea
41174180
return filter(predicate).takeLast(1).singleOrDefault(defaultValue);
41184181
}
41194182

4183+
/**
4184+
* Returns an Observable that emits only the first {@code num} items emitted by the source Observable.
4185+
* <p>
4186+
* Alias of {@link #take(int)} to match Java 8 Stream API naming convention.
4187+
* <p>
4188+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/take.png">
4189+
* <p>
4190+
* 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
4191+
* {@link Observer#onCompleted onCompleted}.
4192+
*
4193+
* @param num
4194+
* the maximum number of items to emit
4195+
* @return an Observable that emits only the first {@code num} items emitted by the source Observable, or
4196+
* all of the items from the source Observable if that Observable emits fewer than {@code num} items
4197+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#wiki-take">RxJava Wiki: take()</a>
4198+
*/
4199+
public final Observable<T> limit(int num) {
4200+
return take(num);
4201+
}
4202+
41204203
/**
41214204
* Returns an Observable that counts the total number of items emitted by the source Observable and emits
41224205
* this count as a 64-bit Long.

0 commit comments

Comments
 (0)