@@ -1054,7 +1054,7 @@ public static <T> Observable<T> from(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T
1054
1054
public static <T > Observable <T > from (T t1 , T t2 , T t3 , T t4 , T t5 , T t6 , T t7 , T t8 , T t9 , T t10 ) {
1055
1055
return from (Arrays .asList (t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ));
1056
1056
}
1057
-
1057
+
1058
1058
/**
1059
1059
* Generates an Observable that emits a sequence of Integers within a
1060
1060
* specified range.
@@ -1930,6 +1930,23 @@ public static <T> Observable<T> switchDo(Observable<? extends Observable<? exten
1930
1930
public static <T > Observable <T > switchOnNext (Observable <? extends Observable <? extends T >> sequenceOfSequences ) {
1931
1931
return create (OperationSwitch .switchDo (sequenceOfSequences ));
1932
1932
}
1933
+
1934
+ /**
1935
+ * Given an Observable that emits Observables, returns an Observable that
1936
+ * emits the items emitted by the most recently emitted of those
1937
+ * Observables.
1938
+ * <p>
1939
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/switchDo.png">
1940
+ *
1941
+ * @param sequenceOfSequences the source Observable that emits Observables
1942
+ * @return an Observable that emits only the items emitted by the Observable
1943
+ * most recently emitted by the source Observable
1944
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#switchonnext">RxJava Wiki: switchOnNext()</a>
1945
+ * @see {@link #switchOnNext(Observable)}
1946
+ */
1947
+ public static <T > Observable <T > switchLatest (Observable <? extends Observable <? extends T >> sequenceOfSequences ) {
1948
+ return create (OperationSwitch .switchDo (sequenceOfSequences ));
1949
+ }
1933
1950
1934
1951
/**
1935
1952
* Return a particular one of several possible Observables based on a case
@@ -3681,7 +3698,7 @@ public Observable<Observable<T>> window(long timespan, long timeshift, TimeUnit
3681
3698
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#zip">RxJava Wiki: zip()</a>
3682
3699
*/
3683
3700
public static <R > Observable <R > zip (Observable <? extends Observable <?>> ws , final FuncN <? extends R > zipFunction ) {
3684
- return ws .toList ().mapMany (new Func1 <List <? extends Observable <?>>, Observable <? extends R >>() {
3701
+ return ws .toList ().mergeMap (new Func1 <List <? extends Observable <?>>, Observable <? extends R >>() {
3685
3702
@ Override
3686
3703
public Observable <R > call (List <? extends Observable <?>> wsList ) {
3687
3704
return create (OperationZip .zip (wsList , zipFunction ));
@@ -3919,7 +3936,64 @@ public Observable<T> finallyDo(Action0 action) {
3919
3936
* @see #mapMany(Func1)
3920
3937
*/
3921
3938
public <R > Observable <R > flatMap (Func1 <? super T , ? extends Observable <? extends R >> func ) {
3922
- return mapMany (func );
3939
+ return mergeMap (func );
3940
+ }
3941
+
3942
+ /**
3943
+ * Creates a new Observable by applying a function that you supply to each
3944
+ * item emitted by the source Observable, where that function returns an
3945
+ * Observable, and then merging those resulting Observables and emitting the
3946
+ * results of this merger.
3947
+ * <p>
3948
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/flatMap.png">
3949
+ * <p>
3950
+ * Note: {@code mapMany} and {@code flatMap} are equivalent.
3951
+ *
3952
+ * @param func a function that, when applied to an item emitted by the
3953
+ * source Observable, returns an Observable
3954
+ * @return an Observable that emits the result of applying the
3955
+ * transformation function to each item emitted by the source
3956
+ * Observable and merging the results of the Observables obtained
3957
+ * from this transformation.
3958
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mapmany-or-flatmap-and-mapmanydelayerror">RxJava Wiki: flatMap()</a>
3959
+ * @see #flatMap(Func1)
3960
+ */
3961
+ public <R > Observable <R > mergeMap (Func1 <? super T , ? extends Observable <? extends R >> func ) {
3962
+ return merge (map (func ));
3963
+ }
3964
+
3965
+ /**
3966
+ * Creates a new Observable by applying a function that you supply to each
3967
+ * item emitted by the source Observable, where that function returns an
3968
+ * Observable, and then concatting those resulting Observables and emitting the
3969
+ * results of this concat.
3970
+ * <p>
3971
+ *
3972
+ * @param func a function that, when applied to an item emitted by the
3973
+ * source Observable, returns an Observable
3974
+ * @return an Observable that emits the result of applying the
3975
+ * transformation function to each item emitted by the source
3976
+ * Observable and concatting the results of the Observables obtained
3977
+ * from this transformation.
3978
+ */
3979
+ public <R > Observable <R > concatMap (Func1 <? super T , ? extends Observable <? extends R >> func ) {
3980
+ return concat (map (func ));
3981
+ }
3982
+
3983
+ /**
3984
+ * Creates a new Observable by applying a function that you supply to each
3985
+ * item emitted by the source Observable resulting in an Observable of Observables.
3986
+ * <p>
3987
+ * Then a {@link #switchLatest(Observable)} / {@link #switchOnNext(Observable)} is applied.
3988
+ *
3989
+ * @param func a function that, when applied to an item emitted by the
3990
+ * source Observable, returns an Observable
3991
+ * @return an Observable that emits the result of applying the
3992
+ * transformation function to each item emitted by the source
3993
+ * Observable and then switch
3994
+ */
3995
+ public <R > Observable <R > switchMap (Func1 <? super T , ? extends Observable <? extends R >> func ) {
3996
+ return switchOnNext (map (func ));
3923
3997
}
3924
3998
3925
3999
/**
@@ -3970,6 +4044,7 @@ public <R> Observable<R> map(Func1<? super T, ? extends R> func) {
3970
4044
* transformed by the given function
3971
4045
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mapwithindex">RxJava Wiki: mapWithIndex()</a>
3972
4046
* @see <a href="http://msdn.microsoft.com/en-us/library/hh244311.aspx">MSDN: Observable.Select</a>
4047
+ * @deprecate just use zip with {@link Observable#range(int)}
3973
4048
*/
3974
4049
public <R > Observable <R > mapWithIndex (Func2 <? super T , Integer , ? extends R > func ) {
3975
4050
return create (OperationMap .mapWithIndex (this , func ));
@@ -3993,9 +4068,10 @@ public <R> Observable<R> mapWithIndex(Func2<? super T, Integer, ? extends R> fun
3993
4068
* from this transformation.
3994
4069
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mapmany-or-flatmap-and-mapmanydelayerror">RxJava Wiki: mapMany()</a>
3995
4070
* @see #flatMap(Func1)
4071
+ * @deprecated
3996
4072
*/
3997
4073
public <R > Observable <R > mapMany (Func1 <? super T , ? extends Observable <? extends R >> func ) {
3998
- return create ( OperationMap . mapMany ( this , func ) );
4074
+ return mergeMap ( func );
3999
4075
}
4000
4076
4001
4077
/**
@@ -5108,6 +5184,7 @@ public ConnectableObservable<T> publishLast() {
5108
5184
*
5109
5185
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#reduce-or-aggregate">RxJava Wiki: aggregate()</a>
5110
5186
* @see #reduce(Func2)
5187
+ * @deprecated
5111
5188
*/
5112
5189
public Observable <T > aggregate (Func2 <T , T , T > accumulator ) {
5113
5190
return reduce (accumulator );
@@ -5150,6 +5227,7 @@ public <R> Observable<R> reduce(R initialValue, Func2<R, ? super T, R> accumulat
5150
5227
*
5151
5228
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#reduce-or-aggregate">RxJava Wiki: aggregate()</a>
5152
5229
* @see #reduce(Object, Func2)
5230
+ * @deprecated
5153
5231
*/
5154
5232
public <R > Observable <R > aggregate (R initialValue , Func2 <R , ? super T , R > accumulator ) {
5155
5233
return reduce (initialValue , accumulator );
@@ -6641,36 +6719,6 @@ public Observable<T> doOnEach(Observer<? super T> observer) {
6641
6719
return create (OperationDoOnEach .doOnEach (this , observer ));
6642
6720
}
6643
6721
6644
- /**
6645
- * Invokes an action for each item emitted by an Observable.
6646
- * <p>
6647
- * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnEach.png">
6648
- *
6649
- * @param onNext the action to invoke for each item emitted by the source
6650
- * Observable
6651
- * @return the source Observable with the side-effecting behavior applied
6652
- * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#dooneach">RxJava Wiki: doOnEach()</a>
6653
- * @see <a href="http://msdn.microsoft.com/en-us/library/hh229804.aspx">MSDN: Observable.Do</a>
6654
- */
6655
- public Observable <T > doOnEach (final Action1 <? super T > onNext ) {
6656
- Observer <T > observer = new Observer <T >() {
6657
- @ Override
6658
- public void onCompleted () {}
6659
-
6660
- @ Override
6661
- public void onError (Throwable e ) {}
6662
-
6663
- @ Override
6664
- public void onNext (T args ) {
6665
- onNext .call (args );
6666
- }
6667
-
6668
- };
6669
-
6670
-
6671
- return create (OperationDoOnEach .doOnEach (this , observer ));
6672
- }
6673
-
6674
6722
/**
6675
6723
* Invokes an action if the source Observable calls <code>onError</code>.
6676
6724
* <p>
@@ -6731,71 +6779,64 @@ public void onNext(T args) { }
6731
6779
6732
6780
return create (OperationDoOnEach .doOnEach (this , observer ));
6733
6781
}
6734
-
6782
+
6783
+
6735
6784
/**
6736
- * Invokes an action for each item emitted by an Observable.
6785
+ * Invokes an action when the source Observable calls
6786
+ * <code>onNext</code>.
6737
6787
* <p>
6738
- * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnEach.e .png">
6788
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnCompleted .png">
6739
6789
*
6740
- * @param onNext the action to invoke for each item emitted by the
6741
- * Observable
6742
- * @param onError the action to invoke when the source Observable calls
6743
- * <code>onError</code>
6790
+ * @param onCompleted the action to invoke when the source Observable calls
6791
+ * <code>onCompleted</code>
6744
6792
* @return the source Observable with the side-effecting behavior applied
6745
- * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#dooneach">RxJava Wiki: doOnEach ()</a>
6746
- * @see <a href="http://msdn.microsoft.com/en-us/library/hh229539 .aspx">MSDN: Observable.Do</a>
6793
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#dooneach">RxJava Wiki: doOnNext ()</a>
6794
+ * @see <a href="http://msdn.microsoft.com/en-us/library/hh229804 .aspx">MSDN: Observable.Do</a>
6747
6795
*/
6748
- public Observable <T > doOnEach (final Action1 <? super T > onNext , final Action1 < Throwable > onError ) {
6796
+ public Observable <T > doOnNext (final Action1 <T > onNext ) {
6749
6797
Observer <T > observer = new Observer <T >() {
6750
6798
@ Override
6751
- public void onCompleted () {}
6799
+ public void onCompleted () { }
6752
6800
6753
6801
@ Override
6754
- public void onError (Throwable e ) {
6755
- onError .call (e );
6756
- }
6802
+ public void onError (Throwable e ) { }
6757
6803
6758
6804
@ Override
6759
- public void onNext (T args ) {
6805
+ public void onNext (T args ) {
6760
6806
onNext .call (args );
6761
6807
}
6762
6808
6763
6809
};
6764
6810
6765
-
6766
6811
return create (OperationDoOnEach .doOnEach (this , observer ));
6767
6812
}
6768
-
6813
+
6769
6814
/**
6770
- * Invokes an action for each item emitted by an Observable.
6815
+ * Invokes an action for each item emitted by the Observable.
6771
6816
* <p>
6772
- * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnEach.ce. png">
6817
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnEach.png">
6773
6818
*
6774
- * @param onNext the action to invoke for each item emitted by the
6775
- * Observable
6776
- * @param onError the action to invoke when the source Observable calls
6777
- * <code>onError</code>
6778
- * @param onCompleted the action to invoke when the source Observable calls
6779
- * <code>onCompleted</code>
6819
+ * @param observer the action to invoke for each item emitted by the source
6820
+ * Observable
6780
6821
* @return the source Observable with the side-effecting behavior applied
6781
6822
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#dooneach">RxJava Wiki: doOnEach()</a>
6782
- * @see <a href="http://msdn.microsoft.com/en-us/library/hh229830 .aspx">MSDN: Observable.Do</a>
6823
+ * @see <a href="http://msdn.microsoft.com/en-us/library/hh229307 .aspx">MSDN: Observable.Do</a>
6783
6824
*/
6784
- public Observable <T > doOnEach (final Action1 <? super T > onNext , final Action1 < Throwable > onError , final Action0 onCompleted ) {
6825
+ public Observable <T > doOnEach (final Action1 <Notification < T >> onNotification ) {
6785
6826
Observer <T > observer = new Observer <T >() {
6786
6827
@ Override
6787
6828
public void onCompleted () {
6788
- onCompleted .call ();
6829
+ onNotification .call (new Notification < T >() );
6789
6830
}
6790
6831
6791
6832
@ Override
6792
6833
public void onError (Throwable e ) {
6793
- onError .call (e );
6834
+ onNotification .call (new Notification < T >( e ) );
6794
6835
}
6795
6836
6796
6837
@ Override
6797
- public void onNext (T args ) {
6798
- onNext .call (args );
6838
+ public void onNext (T v ) {
6839
+ onNotification .call (new Notification < T >( v ) );
6799
6840
}
6800
6841
6801
6842
};
0 commit comments