Skip to content

Commit 04edc95

Browse files
committed
Adds other overrides for doOnEach
1 parent 1db7349 commit 04edc95

File tree

1 file changed

+134
-2
lines changed

1 file changed

+134
-2
lines changed

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

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4782,17 +4782,149 @@ public static <T> Observable<T> amb(Iterable<? extends Observable<? extends T>>
47824782
/**
47834783
* Invokes an action for each element in the observable sequence.
47844784
*
4785-
* @param func
4785+
* @param observer
47864786
* The action to invoke for each element in the source sequence.
47874787
*
47884788
* @return
47894789
* The source sequence with the side-effecting behavior applied.
4790-
* @see <a href="http://msdn.microsoft.com/en-us/library/%3Cspan%20class="x x-first x-last">hh229115(v=vs.103).aspx">MSDN: Observable.Amb</a>
4790+
* @see <a href="http://msdn.microsoft.com/en-us/library/%3Cspan%20class="x x-first x-last">hh229307(v=vs.103).aspx">MSDN: Observable.Do</a>
47914791
*/
47924792
public Observable<T> doOnEach(Observer<? super T> observer) {
47934793
return create(OperationDoOnEach.doOnEach(this, observer));
47944794
}
47954795

4796+
/**
4797+
* Invokes an action for each element in the observable sequence.
4798+
*
4799+
* @param onNext
4800+
* The action to invoke for each element in the source sequence.
4801+
*
4802+
* @return
4803+
* The source sequence with the side-effecting behavior applied.
4804+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229804(v=vs.103).aspx">MSDN: Observable.Do</a>
4805+
*/
4806+
public Observable<T> doOnEach(final Action1<T> onNext) {
4807+
Observer<T> observer = new Observer<T>() {
4808+
@Override
4809+
public void onCompleted() {}
4810+
4811+
@Override
4812+
public void onError(Throwable e) {}
4813+
4814+
@Override
4815+
public void onNext(T args) {
4816+
onNext.call(args);
4817+
}
4818+
4819+
};
4820+
4821+
4822+
return create(OperationDoOnEach.doOnEach(this, observer));
4823+
}
4824+
4825+
/**
4826+
* Invokes an action for each element in the observable sequence.
4827+
*
4828+
* @param onNext
4829+
* The action to invoke for each element in the source sequence.
4830+
* @param onCompleted
4831+
* The action to invoke when the source sequence is completed.
4832+
*
4833+
* @return
4834+
* The source sequence with the side-effecting behavior applied.
4835+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229659(v=vs.103).aspx">MSDN: Observable.Do</a>
4836+
*/
4837+
public Observable<T> doOnEach(final Action1<T> onNext, final Action0 onCompleted) {
4838+
Observer<T> observer = new Observer<T>() {
4839+
@Override
4840+
public void onCompleted() {
4841+
onCompleted.call();
4842+
}
4843+
4844+
@Override
4845+
public void onError(Throwable e) {}
4846+
4847+
@Override
4848+
public void onNext(T args) {
4849+
onNext.call(args);
4850+
}
4851+
4852+
};
4853+
4854+
4855+
return create(OperationDoOnEach.doOnEach(this, observer));
4856+
}
4857+
4858+
/**
4859+
* Invokes an action for each element in the observable sequence.
4860+
*
4861+
* @param onNext
4862+
* The action to invoke for each element in the source sequence.
4863+
* @param onError
4864+
* The action to invoke when the source sequence calls onError.
4865+
*
4866+
* @return
4867+
* The source sequence with the side-effecting behavior applied.
4868+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229539(v=vs.103).aspx">MSDN: Observable.Do</a>
4869+
*/
4870+
public Observable<T> doOnEach(final Action1<T> onNext, final Action1<Throwable> onError) {
4871+
Observer<T> observer = new Observer<T>() {
4872+
@Override
4873+
public void onCompleted() {}
4874+
4875+
@Override
4876+
public void onError(Throwable e) {
4877+
onError.call(e);
4878+
}
4879+
4880+
@Override
4881+
public void onNext(T args) {
4882+
onNext.call(args);
4883+
}
4884+
4885+
};
4886+
4887+
4888+
return create(OperationDoOnEach.doOnEach(this, observer));
4889+
}
4890+
4891+
4892+
/**
4893+
* Invokes an action for each element in the observable sequence.
4894+
*
4895+
* @param onNext
4896+
* The action to invoke for each element in the source sequence.
4897+
* @param onError
4898+
* The action to invoke when the source sequence calls onError.
4899+
* @param onCompleted
4900+
* The action to invoke when the source sequence is completed.
4901+
*
4902+
* @return
4903+
* The source sequence with the side-effecting behavior applied.
4904+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229830(v=vs.103).aspx">MSDN: Observable.Do</a>
4905+
*/
4906+
public Observable<T> doOnEach(final Action1<T> onNext, final Action1<Throwable> onError, final Action0 onCompleted) {
4907+
Observer<T> observer = new Observer<T>() {
4908+
@Override
4909+
public void onCompleted() {
4910+
onCompleted.call();
4911+
}
4912+
4913+
@Override
4914+
public void onError(Throwable e) {
4915+
onError.call(e);
4916+
}
4917+
4918+
@Override
4919+
public void onNext(T args) {
4920+
onNext.call(args);
4921+
}
4922+
4923+
};
4924+
4925+
4926+
return create(OperationDoOnEach.doOnEach(this, observer));
4927+
}
47964928

47974929
/**
47984930
* Whether a given {@link Function} is an internal implementation inside rx.* packages or not.

0 commit comments

Comments
 (0)