@@ -4738,7 +4738,118 @@ public final Observable<T> firstOrDefault(T defaultValue, Func1<? super T, Boole
4738
4738
* @see <a href="http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable.selectmany.aspx">MSDN: Observable.SelectMany</a>
4739
4739
*/
4740
4740
public final <R> Observable<R> flatMap(Func1<? super T, ? extends Observable<? extends R>> func) {
4741
- return mergeMap(func);
4741
+ return merge(map(func));
4742
+ }
4743
+
4744
+ /**
4745
+ * Returns an Observable that applies a function to each item emitted or notification raised by the source
4746
+ * Observable and then flattens the Observables returned from these functions and emits the resulting items.
4747
+ * <p>
4748
+ * <img width="640" height="410" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/mergeMap.nce.png" alt="">
4749
+ * <dl>
4750
+ * <dt><b>Scheduler:</b></dt>
4751
+ * <dd>{@code mergeMap} does not operate by default on a particular {@link Scheduler}.</dd>
4752
+ * </dl>
4753
+ *
4754
+ * @param <R>
4755
+ * the result type
4756
+ * @param onNext
4757
+ * a function that returns an Observable to merge for each item emitted by the source Observable
4758
+ * @param onError
4759
+ * a function that returns an Observable to merge for an onError notification from the source
4760
+ * Observable
4761
+ * @param onCompleted
4762
+ * a function that returns an Observable to merge for an onCompleted notification from the source
4763
+ * Observable
4764
+ * @return an Observable that emits the results of merging the Observables returned from applying the
4765
+ * specified functions to the emissions and notifications of the source Observable
4766
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMap</a>
4767
+ */
4768
+ public final <R> Observable<R> flatMap(
4769
+ Func1<? super T, ? extends Observable<? extends R>> onNext,
4770
+ Func1<? super Throwable, ? extends Observable<? extends R>> onError,
4771
+ Func0<? extends Observable<? extends R>> onCompleted) {
4772
+ return merge(mapNotification(onNext, onError, onCompleted));
4773
+ }
4774
+
4775
+ /**
4776
+ * Returns an Observable that emits the results of a specified function to the pair of values emitted by the
4777
+ * source Observable and a specified collection Observable.
4778
+ * <p>
4779
+ * <img width="640" height="390" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/mergeMap.r.png" alt="">
4780
+ * <dl>
4781
+ * <dt><b>Scheduler:</b></dt>
4782
+ * <dd>{@code mergeMap} does not operate by default on a particular {@link Scheduler}.</dd>
4783
+ * </dl>
4784
+ *
4785
+ * @param <U>
4786
+ * the type of items emitted by the collection Observable
4787
+ * @param <R>
4788
+ * the type of items emitted by the resulting Observable
4789
+ * @param collectionSelector
4790
+ * a function that returns an Observable for each item emitted by the source Observable
4791
+ * @param resultSelector
4792
+ * a function that combines one item emitted by each of the source and collection Observables and
4793
+ * returns an item to be emitted by the resulting Observable
4794
+ * @return an Observable that emits the results of applying a function to a pair of values emitted by the
4795
+ * source Observable and the collection Observable
4796
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMap</a>
4797
+ */
4798
+ public final <U, R> Observable<R> flatMap(final Func1<? super T, ? extends Observable<? extends U>> collectionSelector,
4799
+ final Func2<? super T, ? super U, ? extends R> resultSelector) {
4800
+ return merge(lift(new OperatorMapPair<T, U, R>(collectionSelector, resultSelector)));
4801
+ }
4802
+
4803
+ /**
4804
+ * Returns an Observable that merges each item emitted by the source Observable with the values in an
4805
+ * Iterable corresponding to that item that is generated by a selector.
4806
+ * <p>
4807
+ * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
4808
+ * <dl>
4809
+ * <dt><b>Scheduler:</b></dt>
4810
+ * <dd>{@code mergeMapIterable} does not operate by default on a particular {@link Scheduler}.</dd>
4811
+ * </dl>
4812
+ *
4813
+ * @param <R>
4814
+ * the type of item emitted by the resulting Observable
4815
+ * @param collectionSelector
4816
+ * a function that returns an Iterable sequence of values for when given an item emitted by the
4817
+ * source Observable
4818
+ * @return an Observable that emits the results of merging the items emitted by the source Observable with
4819
+ * the values in the Iterables corresponding to those items, as generated by {@code collectionSelector}
4820
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMapIterable</a>
4821
+ */
4822
+ public final <R> Observable<R> flatMapIterable(Func1<? super T, ? extends Iterable<? extends R>> collectionSelector) {
4823
+ return merge(map(OperatorMapPair.convertSelector(collectionSelector)));
4824
+ }
4825
+
4826
+ /**
4827
+ * Returns an Observable that emits the results of applying a function to the pair of values from the source
4828
+ * Observable and an Iterable corresponding to that item that is generated by a selector.
4829
+ * <p>
4830
+ * <img width="640" height="390" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/mergeMapIterable.r.png" alt="">
4831
+ * <dl>
4832
+ * <dt><b>Scheduler:</b></dt>
4833
+ * <dd>{@code mergeMapIterable} does not operate by default on a particular {@link Scheduler}.</dd>
4834
+ * </dl>
4835
+ *
4836
+ * @param <U>
4837
+ * the collection element type
4838
+ * @param <R>
4839
+ * the type of item emited by the resulting Observable
4840
+ * @param collectionSelector
4841
+ * a function that returns an Iterable sequence of values for each item emitted by the source
4842
+ * Observable
4843
+ * @param resultSelector
4844
+ * a function that returns an item based on the item emitted by the source Observable and the
4845
+ * Iterable returned for that item by the {@code collectionSelector}
4846
+ * @return an Observable that emits the items returned by {@code resultSelector} for each item in the source
4847
+ * Observable
4848
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMapIterable</a>
4849
+ */
4850
+ public final <U, R> Observable<R> flatMapIterable(Func1<? super T, ? extends Iterable<? extends U>> collectionSelector,
4851
+ Func2<? super T, ? super U, ? extends R> resultSelector) {
4852
+ return flatMap(OperatorMapPair.convertSelector(collectionSelector), resultSelector);
4742
4853
}
4743
4854
4744
4855
/**
@@ -5225,7 +5336,9 @@ public final Observable<Notification<T>> materialize() {
5225
5336
* transformations
5226
5337
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMap</a>
5227
5338
* @see #flatMap(Func1)
5339
+ * @deprecated use flatMap
5228
5340
*/
5341
+ @Deprecated
5229
5342
public final <R> Observable<R> mergeMap(Func1<? super T, ? extends Observable<? extends R>> func) {
5230
5343
return merge(map(func));
5231
5344
}
@@ -5253,7 +5366,9 @@ public final <R> Observable<R> mergeMap(Func1<? super T, ? extends Observable<?
5253
5366
* @return an Observable that emits the results of merging the Observables returned from applying the
5254
5367
* specified functions to the emissions and notifications of the source Observable
5255
5368
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMap</a>
5369
+ * @deprecated use flatMap
5256
5370
*/
5371
+ @Deprecated
5257
5372
public final <R> Observable<R> mergeMap(
5258
5373
Func1<? super T, ? extends Observable<? extends R>> onNext,
5259
5374
Func1<? super Throwable, ? extends Observable<? extends R>> onError,
@@ -5283,10 +5398,12 @@ public final <R> Observable<R> mergeMap(
5283
5398
* @return an Observable that emits the results of applying a function to a pair of values emitted by the
5284
5399
* source Observable and the collection Observable
5285
5400
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMap</a>
5401
+ * @deprecated use flatMap
5286
5402
*/
5403
+ @Deprecated
5287
5404
public final <U, R> Observable<R> mergeMap(Func1<? super T, ? extends Observable<? extends U>> collectionSelector,
5288
5405
Func2<? super T, ? super U, ? extends R> resultSelector) {
5289
- return lift(new OperatorMergeMapPair<T, U, R>( collectionSelector, resultSelector) );
5406
+ return flatMap( collectionSelector, resultSelector);
5290
5407
}
5291
5408
5292
5409
/**
@@ -5307,9 +5424,11 @@ public final <U, R> Observable<R> mergeMap(Func1<? super T, ? extends Observable
5307
5424
* @return an Observable that emits the results of merging the items emitted by the source Observable with
5308
5425
* the values in the Iterables corresponding to those items, as generated by {@code collectionSelector}
5309
5426
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMapIterable</a>
5427
+ * @deprecated use flatMapIterable
5310
5428
*/
5429
+ @Deprecated
5311
5430
public final <R> Observable<R> mergeMapIterable(Func1<? super T, ? extends Iterable<? extends R>> collectionSelector) {
5312
- return merge(map(OperatorMergeMapPair .convertSelector(collectionSelector)));
5431
+ return merge(map(OperatorMapPair .convertSelector(collectionSelector)));
5313
5432
}
5314
5433
5315
5434
/**
@@ -5335,10 +5454,12 @@ public final <R> Observable<R> mergeMapIterable(Func1<? super T, ? extends Itera
5335
5454
* @return an Observable that emits the items returned by {@code resultSelector} for each item in the source
5336
5455
* Observable
5337
5456
* @see <a href="https://github.com/Netflix/RxJava/wiki/Transforming-Observables#mergemap-and-mergemapiterable">RxJava wiki: mergeMapIterable</a>
5457
+ * @deprecated use flatMapIterable
5338
5458
*/
5459
+ @Deprecated
5339
5460
public final <U, R> Observable<R> mergeMapIterable(Func1<? super T, ? extends Iterable<? extends U>> collectionSelector,
5340
5461
Func2<? super T, ? super U, ? extends R> resultSelector) {
5341
- return mergeMap(OperatorMergeMapPair .convertSelector(collectionSelector), resultSelector);
5462
+ return mergeMap(OperatorMapPair .convertSelector(collectionSelector), resultSelector);
5342
5463
}
5343
5464
5344
5465
/**
0 commit comments