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

Operator forIterable 2 #668

Closed
wants to merge 1 commit into from
Closed

Conversation

akarnokd
Copy link
Member

Split from #636

This operator behaves differently than concat(Iterable). It allows projecting a potentially infinite sequence onto Observables concatenated one after each other. The input Iterable sequence is not traversed upfront like concat(Iterable) and concat(Observable) would do.

@cloudbees-pull-request-builder

RxJava-pull-requests #602 FAILURE
Looks like there's a problem with this pull request

@benjchristensen
Copy link
Member

I believe what you want is accomplished with concatMap that was recently added.

        Observable<Integer> result = Observable.from(keys).concatMap(new Func1<Integer, Observable<Integer>>() {

            @Override
            public Observable<Integer> call(Integer t1) {
                return Observable.from(1, 2, 3).subscribeOn(Schedulers.currentThread());
            }});

Here is a unit test from your code converted to this and it passes:

    @Test
    public void testForIterableLongSequence() {
        int n = 250;
        List<Integer> keys = new ArrayList<Integer>(n);
        List<Integer> expected = new ArrayList<Integer>(3 * n);
        for (int i = 1; i <= n; i++) {
            keys.add(n);
            for (int j = 1; j <= 3; j++) {
                expected.add(j);
            }
        }

        Observable<Integer> result = Observable.from(keys).concatMap(new Func1<Integer, Observable<Integer>>() {

            @Override
            public Observable<Integer> call(Integer t1) {
                return Observable.from(1, 2, 3).subscribeOn(Schedulers.currentThread());
            }});

        Observer<Object> o = mock(Observer.class);
        InOrder inOrder = inOrder(o);

        result.subscribe(o);

        for (Integer i : expected) {
            inOrder.verify(o, times(1)).onNext(i);
        }
        inOrder.verify(o, times(1)).onCompleted();
        inOrder.verifyNoMoreInteractions();
        verify(o, never()).onError(any(Throwable.class));

    }

@akarnokd
Copy link
Member Author

True. Since the newer ConcatMap does the same thing, this PR can be skipped.

@akarnokd akarnokd deleted the ForEachIterable2 branch January 13, 2014 09:56
jihoonson pushed a commit to jihoonson/RxJava that referenced this pull request Mar 6, 2020
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.

3 participants