Skip to content

Commit

Permalink
2.x: add flattenAs{Observable,Flowable} to Single and Maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd committed Sep 28, 2016
1 parent c3a1d91 commit 6ed0062
Show file tree
Hide file tree
Showing 13 changed files with 1,468 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/main/java/io/reactivex/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8281,7 +8281,7 @@ public final <U, R> Flowable<R> flatMap(Function<? super T, ? extends Publisher<
* </dl>
*
* @param <U>
* the type of item emitted by the resulting Publisher
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for when given an item emitted by the
* source Publisher
Expand Down Expand Up @@ -8310,7 +8310,7 @@ public final <U> Flowable<U> flatMapIterable(final Function<? super T, ? extends
* </dl>
*
* @param <U>
* the type of item emitted by the resulting Publisher
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for when given an item emitted by the
* source Publisher
Expand Down Expand Up @@ -8344,7 +8344,7 @@ public final <U> Flowable<U> flatMapIterable(final Function<? super T, ? extends
* @param <U>
* the collection element type
* @param <V>
* the type of item emitted by the resulting Publisher
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for each item emitted by the source
* Publisher
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,54 @@ public final <U, R> Maybe<R> flatMap(Function<? super T, ? extends MaybeSource<?
return RxJavaPlugins.onAssembly(new MaybeFlatMapBiSelector<T, U, R>(this, mapper, resultSelector));
}

/**
* Returns a Flowable that merges each item emitted by the source Maybe with the values in an
* Iterable corresponding to that item that is generated by a selector.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator honors backpressure from downstream.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code flatMapIterable} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param <U>
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for when given an item emitted by the
* source Maybe
* @return the new Flowable instance
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
*/
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
public final <U> Flowable<U> flattenAsFlowable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
return new MaybeFlatMapIterableFlowable<T, U>(this, mapper);
}

/**
* Returns an Observable that maps a success value into an Iterable and emits its items.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code flattenIterable} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param <U>
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for when given an item emitted by the
* source Maybe
* @return the new Observable instance
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final <U> Observable<U> flattenAsObservable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
return new MaybeFlatMapIterableObservable<T, U>(this, mapper);
}

/**
* Returns an Observable that is based on applying a specified function to the item emitted by the source Maybe,
* where that function returns an ObservableSource.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7177,7 +7177,7 @@ public final <U, R> Observable<R> flatMap(Function<? super T, ? extends Observab
* </dl>
*
* @param <U>
* the type of item emitted by the resulting ObservableSource
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for when given an item emitted by the
* source ObservableSource
Expand All @@ -7204,7 +7204,7 @@ public final <U> Observable<U> flatMapIterable(final Function<? super T, ? exten
* @param <U>
* the collection element type
* @param <V>
* the type of item emitted by the resulting ObservableSource
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for each item emitted by the source
* ObservableSource
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,59 @@ public final <R> Flowable<R> flatMapPublisher(Function<? super T, ? extends Publ
}

/**
<<<<<<< HEAD
* Returns an Observable that is based on applying a specified function to the item emitted by the source Single,
=======
* Returns a Flowable that merges each item emitted by the source Single with the values in an
* Iterable corresponding to that item that is generated by a selector.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator honors backpressure from downstream.</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code flatMapIterable} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param <U>
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for when given an item emitted by the
* source Single
* @return the new Flowable instance
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
*/
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
public final <U> Flowable<U> flattenAsFlowable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
return new SingleFlatMapIterableFlowable<T, U>(this, mapper);
}

/**
* Returns an Observable that maps a success value into an Iterable and emits its items.
* <p>
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/mergeMapIterable.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code flattenIterable} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param <U>
* the type of item emitted by the resulting Iterable
* @param mapper
* a function that returns an Iterable sequence of values for when given an item emitted by the
* source Single
* @return the new Observable instance
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final <U> Observable<U> flattenAsObservable(final Function<? super T, ? extends Iterable<? extends U>> mapper) {
return new SingleFlatMapIterableObservable<T, U>(this, mapper);
}

/**
* Returns a Single that is based on applying a specified function to the item emitted by the source Single,
>>>>>>> refs/remotes/akarnokd/SoloFlatMapIterable
* where that function returns a SingleSource.
* <p>
* <img width="640" height="300" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.flatMap.png" alt="">
Expand Down
Loading

0 comments on commit 6ed0062

Please sign in to comment.