Skip to content

MergeMap with Iterable and resultSelector overloads#736

Merged
benjchristensen merged 2 commits intoReactiveX:masterfrom
akarnokd:FlatMapOverloads
Jan 14, 2014
Merged

MergeMap with Iterable and resultSelector overloads#736
benjchristensen merged 2 commits intoReactiveX:masterfrom
akarnokd:FlatMapOverloads

Conversation

@akarnokd
Copy link
Member

Listed in #653.

@akarnokd akarnokd mentioned this pull request Jan 10, 2014
25 tasks
@akarnokd
Copy link
Member Author

Forgot an overload.

@akarnokd akarnokd closed this Jan 10, 2014
@cloudbees-pull-request-builder

RxJava-pull-requests #650 SUCCESS
This pull request looks good

@akarnokd akarnokd reopened this Jan 10, 2014
@cloudbees-pull-request-builder

RxJava-pull-requests #651 SUCCESS
This pull request looks good

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
        }
    }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to introduce Pair for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use any better class to replace Pair. However, I think we do not need to reimplement flatMap again here.

@zsxwing
Copy link
Member

zsxwing commented Jan 13, 2014

Looks these operators can be implemented by composing the existing operators.

@benjchristensen
Copy link
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
@benjchristensen benjchristensen merged commit 17307e4 into ReactiveX:master Jan 14, 2014
@akarnokd akarnokd deleted the FlatMapOverloads branch May 6, 2014 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants