Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: add flattenAs{Observable,Flowable} to Single and Maybe #4604

Merged
merged 1 commit into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 flattenAsFlowable} 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 flattenAsObservable} 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
51 changes: 50 additions & 1 deletion src/main/java/io/reactivex/Single.java
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,56 @@ public final <R> Flowable<R> flatMapPublisher(Function<? super T, ? extends Publ
}

/**
* 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 flattenAsFlowable} 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 flattenAsObservable} 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