@@ -1635,8 +1635,9 @@ public final static <T> Observable<T> merge(Iterable<? extends Observable<? exte
1635
1635
* {@code source} Observable
1636
1636
* @see <a href="http://reactivex.io/documentation/operators/merge.html">ReactiveX operators documentation: Merge</a>
1637
1637
*/
1638
+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
1638
1639
public final static <T > Observable <T > merge (Observable <? extends Observable <? extends T >> source ) {
1639
- return source .lift ( OperatorMerge .< T > instance ( false ));
1640
+ return source .flatMap (( Func1 ) UtilityFunctions . identity ( ));
1640
1641
}
1641
1642
1642
1643
/**
@@ -1664,8 +1665,9 @@ public final static <T> Observable<T> merge(Observable<? extends Observable<? ex
1664
1665
* @see <a href="http://reactivex.io/documentation/operators/merge.html">ReactiveX operators documentation: Merge</a>
1665
1666
*/
1666
1667
@ Experimental
1668
+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
1667
1669
public final static <T > Observable <T > merge (Observable <? extends Observable <? extends T >> source , int maxConcurrent ) {
1668
- return source .lift ( OperatorMerge .< T > instance ( false , maxConcurrent ) );
1670
+ return source .flatMap (( Func1 ) UtilityFunctions . identity () , maxConcurrent );
1669
1671
}
1670
1672
1671
1673
/**
@@ -1985,8 +1987,9 @@ public final static <T> Observable<T> merge(Observable<? extends T>[] sequences,
1985
1987
* {@code source} Observable
1986
1988
* @see <a href="http://reactivex.io/documentation/operators/merge.html">ReactiveX operators documentation: Merge</a>
1987
1989
*/
1990
+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
1988
1991
public final static <T > Observable <T > mergeDelayError (Observable <? extends Observable <? extends T >> source ) {
1989
- return source .lift ( OperatorMerge .< T > instance ( true ) );
1992
+ return source .flatMap (( Func1 ) UtilityFunctions . identity (), Integer . MAX_VALUE , true );
1990
1993
}
1991
1994
/**
1992
1995
* Flattens an Observable that emits Observables into one Observable, in a way that allows an Observer to
@@ -2016,8 +2019,9 @@ public final static <T> Observable<T> mergeDelayError(Observable<? extends Obser
2016
2019
* @see <a href="http://reactivex.io/documentation/operators/merge.html">ReactiveX operators documentation: Merge</a>
2017
2020
*/
2018
2021
@ Experimental
2022
+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
2019
2023
public final static <T > Observable <T > mergeDelayError (Observable <? extends Observable <? extends T >> source , int maxConcurrent ) {
2020
- return source .lift ( OperatorMerge .< T > instance ( true , maxConcurrent ) );
2024
+ return source .flatMap (( Func1 ) UtilityFunctions . identity () , maxConcurrent , true );
2021
2025
}
2022
2026
2023
2027
/**
@@ -4614,7 +4618,7 @@ public final Observable<T> firstOrDefault(T defaultValue, Func1<? super T, Boole
4614
4618
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
4615
4619
*/
4616
4620
public final <R > Observable <R > flatMap (Func1 <? super T , ? extends Observable <? extends R >> func ) {
4617
- return merge ( map ( func ));
4621
+ return lift ( OperatorMerge . instance ( false , Integer . MAX_VALUE , func ));
4618
4622
}
4619
4623
4620
4624
/**
@@ -4642,7 +4646,67 @@ public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? e
4642
4646
*/
4643
4647
@ Beta
4644
4648
public final <R > Observable <R > flatMap (Func1 <? super T , ? extends Observable <? extends R >> func , int maxConcurrent ) {
4645
- return merge (map (func ), maxConcurrent );
4649
+ return flatMap (func , maxConcurrent , false );
4650
+ }
4651
+
4652
+ /**
4653
+ * Returns an Observable that emits items based on applying a function that you supply to each item emitted
4654
+ * by the source Observable, where that function returns an Observable, and then merging those resulting
4655
+ * Observables and emitting the results of this merger, while limiting the maximum number of concurrent
4656
+ * subscriptions to these Observables.
4657
+ * <p>
4658
+ * <!-- <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/flatMap.png" alt=""> -->
4659
+ * <dl>
4660
+ * <dt><b>Scheduler:</b></dt>
4661
+ * <dd>{@code flatMap} does not operate by default on a particular {@link Scheduler}.</dd>
4662
+ * </dl>
4663
+ *
4664
+ * @param func
4665
+ * a function that, when applied to an item emitted by the source Observable, returns an
4666
+ * Observable
4667
+ * @param maxConcurrent
4668
+ * the maximum number of Observables that may be subscribed to concurrently
4669
+ * @param delayErrors
4670
+ * should the errors delayed until all sources have terminated in some way
4671
+ * @return an Observable that emits the result of applying the transformation function to each item emitted
4672
+ * by the source Observable and merging the results of the Observables obtained from this
4673
+ * transformation
4674
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
4675
+ * @since (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
4676
+ */
4677
+ @ Beta
4678
+ public final <R > Observable <R > flatMap (Func1 <? super T , ? extends Observable <? extends R >> func , int maxConcurrent , boolean delayErrors ) {
4679
+ return lift (OperatorMerge .instance (delayErrors , maxConcurrent , func ));
4680
+ }
4681
+
4682
+ /**
4683
+ * Returns an Observable that emits items based on applying a function that you supply to each item emitted
4684
+ * by the source Observable, where that function returns an Observable, and then merging those resulting
4685
+ * Observables and emitting the results of this merger, while limiting the maximum number of concurrent
4686
+ * subscriptions to these Observables.
4687
+ * <p>
4688
+ * <!-- <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/flatMap.png" alt=""> -->
4689
+ * <dl>
4690
+ * <dt><b>Scheduler:</b></dt>
4691
+ * <dd>{@code flatMap} does not operate by default on a particular {@link Scheduler}.</dd>
4692
+ * </dl>
4693
+ *
4694
+ * @param func
4695
+ * a function that, when applied to an item emitted by the source Observable, returns an
4696
+ * Observable
4697
+ * @param maxConcurrent
4698
+ * the maximum number of Observables that may be subscribed to concurrently
4699
+ * @param delayErrors
4700
+ * should the errors delayed until all sources have terminated in some way
4701
+ * @return an Observable that emits the result of applying the transformation function to each item emitted
4702
+ * by the source Observable and merging the results of the Observables obtained from this
4703
+ * transformation
4704
+ * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
4705
+ * @since (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
4706
+ */
4707
+ @ Beta
4708
+ public final <R > Observable <R > flatMap (Func1 <? super T , ? extends Observable <? extends R >> func , boolean delayErrors ) {
4709
+ return lift (OperatorMerge .instance (delayErrors , Integer .MAX_VALUE , func ));
4646
4710
}
4647
4711
4648
4712
/**
@@ -4791,7 +4855,7 @@ public final <U, R> Observable<R> flatMap(final Func1<? super T, ? extends Obser
4791
4855
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
4792
4856
*/
4793
4857
public final <R > Observable <R > flatMapIterable (Func1 <? super T , ? extends Iterable <? extends R >> collectionSelector ) {
4794
- return merge ( map ( OperatorMapPair .convertSelector (collectionSelector ) ));
4858
+ return flatMap ( OperatorMapPair .convertSelector (collectionSelector ));
4795
4859
}
4796
4860
4797
4861
/**
0 commit comments