Skip to content

Commit d6a8461

Browse files
authored
2.x: add flattenAs{Observable,Flowable} to Single and Maybe (#4604)
1 parent 25efd1c commit d6a8461

13 files changed

+1466
-9
lines changed

src/main/java/io/reactivex/Flowable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8281,7 +8281,7 @@ public final <U, R> Flowable<R> flatMap(Function<? super T, ? extends Publisher<
82818281
* </dl>
82828282
*
82838283
* @param <U>
8284-
* the type of item emitted by the resulting Publisher
8284+
* the type of item emitted by the resulting Iterable
82858285
* @param mapper
82868286
* a function that returns an Iterable sequence of values for when given an item emitted by the
82878287
* source Publisher
@@ -8310,7 +8310,7 @@ public final <U> Flowable<U> flatMapIterable(final Function<? super T, ? extends
83108310
* </dl>
83118311
*
83128312
* @param <U>
8313-
* the type of item emitted by the resulting Publisher
8313+
* the type of item emitted by the resulting Iterable
83148314
* @param mapper
83158315
* a function that returns an Iterable sequence of values for when given an item emitted by the
83168316
* source Publisher
@@ -8344,7 +8344,7 @@ public final <U> Flowable<U> flatMapIterable(final Function<? super T, ? extends
83448344
* @param <U>
83458345
* the collection element type
83468346
* @param <V>
8347-
* the type of item emitted by the resulting Publisher
8347+
* the type of item emitted by the resulting Iterable
83488348
* @param mapper
83498349
* a function that returns an Iterable sequence of values for each item emitted by the source
83508350
* Publisher

src/main/java/io/reactivex/Maybe.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,54 @@ public final <U, R> Maybe<R> flatMap(Function<? super T, ? extends MaybeSource<?
25062506
return RxJavaPlugins.onAssembly(new MaybeFlatMapBiSelector<T, U, R>(this, mapper, resultSelector));
25072507
}
25082508

2509+
/**
2510+
* Returns a Flowable that merges each item emitted by the source Maybe with the values in an
2511+
* Iterable corresponding to that item that is generated by a selector.
2512+
* <p>
2513+
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
2514+
* <dl>
2515+
* <dt><b>Backpressure:</b></dt>
2516+
* <dd>The operator honors backpressure from downstream.</dd>
2517+
* <dt><b>Scheduler:</b></dt>
2518+
* <dd>{@code flattenAsFlowable} does not operate by default on a particular {@link Scheduler}.</dd>
2519+
* </dl>
2520+
*
2521+
* @param <U>
2522+
* the type of item emitted by the resulting Iterable
2523+
* @param mapper
2524+
* a function that returns an Iterable sequence of values for when given an item emitted by the
2525+
* source Maybe
2526+
* @return the new Flowable instance
2527+
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
2528+
*/
2529+
@BackpressureSupport(BackpressureKind.FULL)
2530+
@SchedulerSupport(SchedulerSupport.NONE)
2531+
public final <U> Flowable<U> flattenAsFlowable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
2532+
return new MaybeFlatMapIterableFlowable<T, U>(this, mapper);
2533+
}
2534+
2535+
/**
2536+
* Returns an Observable that maps a success value into an Iterable and emits its items.
2537+
* <p>
2538+
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
2539+
* <dl>
2540+
* <dt><b>Scheduler:</b></dt>
2541+
* <dd>{@code flattenAsObservable} does not operate by default on a particular {@link Scheduler}.</dd>
2542+
* </dl>
2543+
*
2544+
* @param <U>
2545+
* the type of item emitted by the resulting Iterable
2546+
* @param mapper
2547+
* a function that returns an Iterable sequence of values for when given an item emitted by the
2548+
* source Maybe
2549+
* @return the new Observable instance
2550+
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
2551+
*/
2552+
@SchedulerSupport(SchedulerSupport.NONE)
2553+
public final <U> Observable<U> flattenAsObservable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
2554+
return new MaybeFlatMapIterableObservable<T, U>(this, mapper);
2555+
}
2556+
25092557
/**
25102558
* Returns an Observable that is based on applying a specified function to the item emitted by the source Maybe,
25112559
* where that function returns an ObservableSource.

src/main/java/io/reactivex/Observable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7177,7 +7177,7 @@ public final <U, R> Observable<R> flatMap(Function<? super T, ? extends Observab
71777177
* </dl>
71787178
*
71797179
* @param <U>
7180-
* the type of item emitted by the resulting ObservableSource
7180+
* the type of item emitted by the resulting Iterable
71817181
* @param mapper
71827182
* a function that returns an Iterable sequence of values for when given an item emitted by the
71837183
* source ObservableSource
@@ -7204,7 +7204,7 @@ public final <U> Observable<U> flatMapIterable(final Function<? super T, ? exten
72047204
* @param <U>
72057205
* the collection element type
72067206
* @param <V>
7207-
* the type of item emitted by the resulting ObservableSource
7207+
* the type of item emitted by the resulting Iterable
72087208
* @param mapper
72097209
* a function that returns an Iterable sequence of values for each item emitted by the source
72107210
* ObservableSource

src/main/java/io/reactivex/Single.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,56 @@ public final <R> Flowable<R> flatMapPublisher(Function<? super T, ? extends Publ
18751875
}
18761876

18771877
/**
1878-
* Returns an Observable that is based on applying a specified function to the item emitted by the source Single,
1878+
* Returns a Flowable that merges each item emitted by the source Single with the values in an
1879+
* Iterable corresponding to that item that is generated by a selector.
1880+
* <p>
1881+
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
1882+
* <dl>
1883+
* <dt><b>Backpressure:</b></dt>
1884+
* <dd>The operator honors backpressure from downstream.</dd>
1885+
* <dt><b>Scheduler:</b></dt>
1886+
* <dd>{@code flattenAsFlowable} does not operate by default on a particular {@link Scheduler}.</dd>
1887+
* </dl>
1888+
*
1889+
* @param <U>
1890+
* the type of item emitted by the resulting Iterable
1891+
* @param mapper
1892+
* a function that returns an Iterable sequence of values for when given an item emitted by the
1893+
* source Single
1894+
* @return the new Flowable instance
1895+
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1896+
*/
1897+
@BackpressureSupport(BackpressureKind.FULL)
1898+
@SchedulerSupport(SchedulerSupport.NONE)
1899+
public final <U> Flowable<U> flattenAsFlowable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
1900+
return new SingleFlatMapIterableFlowable<T, U>(this, mapper);
1901+
}
1902+
1903+
/**
1904+
* Returns an Observable that maps a success value into an Iterable and emits its items.
1905+
* <p>
1906+
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
1907+
* <dl>
1908+
* <dt><b>Scheduler:</b></dt>
1909+
* <dd>{@code flattenAsObservable} does not operate by default on a particular {@link Scheduler}.</dd>
1910+
* </dl>
1911+
*
1912+
* @param <U>
1913+
* the type of item emitted by the resulting Iterable
1914+
* @param mapper
1915+
* a function that returns an Iterable sequence of values for when given an item emitted by the
1916+
* source Single
1917+
* @return the new Observable instance
1918+
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
1919+
*/
1920+
@SchedulerSupport(SchedulerSupport.NONE)
1921+
public final <U> Observable<U> flattenAsObservable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
1922+
return new SingleFlatMapIterableObservable<T, U>(this, mapper);
1923+
}
1924+
1925+
/**
1926+
* Returns a Single that is based on applying a specified function to the item emitted by the source Single,
1927+
>>>>>>> refs/remotes/akarnokd/SoloFlatMapIterable
18791928
* where that function returns a SingleSource.
18801929
* <p>
18811930
* <img width="640" height="300" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.flatMap.png" alt="">

0 commit comments

Comments
 (0)