MergeMap with Iterable and resultSelector overloads#736
Merged
benjchristensen merged 2 commits intoReactiveX:masterfrom Jan 14, 2014
Merged
MergeMap with Iterable and resultSelector overloads#736benjchristensen merged 2 commits intoReactiveX:masterfrom
benjchristensen merged 2 commits intoReactiveX:masterfrom
Conversation
Member
Author
|
Forgot an overload. |
|
RxJava-pull-requests #650 SUCCESS |
|
RxJava-pull-requests #651 SUCCESS |
Member
There was a problem hiding this comment.
Looks it can be implemented by a simple class Pair, for example:
public <U, R> Observable<R> mergeMap(final Func1<? super T, ? extends Observable<? extends U>> collectionSelector,
final Func2<? super T, ? super U, ? extends R> resultSelector) {
return flatMap(new Func1<T, Observable<Pair<T, U>>>() {
@Override
public Observable<Pair<T, U>> call(final T t) {
return collectionSelector.call(t).map(new Func1<U, Pair<T, U>>() {
@Override
public Pair<T, U> call(U u) {
return new Pair<T, U>(t, u);
}
});
}
}).map(new Func1<Pair<T, U>, R>() {
@Override
public R call(Pair<T, U> pair) {
return resultSelector.call(pair._1, pair._2);
}
});
}
private static class Pair<T1, T2> {
T1 _1;
T2 _2;
Pair(T1 _1, T2 _2) {
this._1 = _1;
this._2 = _2;
}
}
Member
Author
There was a problem hiding this comment.
I didn't want to introduce Pair for this.
Member
There was a problem hiding this comment.
You can use any better class to replace Pair. However, I think we do not need to reimplement flatMap again here.
Member
|
Looks these operators can be implemented by composing the existing operators. |
Member
|
I agree there is likely some simplification we can do on this, but I'm going to merge as the public APIs look correct and unit tests are good. We can iterate on the implementation internally. |
benjchristensen
added a commit
that referenced
this pull request
Jan 14, 2014
MergeMap with Iterable and resultSelector overloads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Listed in #653.