Skip to content

BugFix: Reduce an empty observable#474

Merged
benjchristensen merged 1 commit intoReactiveX:masterfrom
benjchristensen:issue-423-reduce-empty-observable
Nov 7, 2013
Merged

BugFix: Reduce an empty observable#474
benjchristensen merged 1 commit intoReactiveX:masterfrom
benjchristensen:issue-423-reduce-empty-observable

Conversation

@benjchristensen
Copy link
Member

This fixes issue #423

The fix is based on this comment by @headinthebox: #423 (comment)

Thank you @zsxwing for your involvement on this.

If I have mis-interpreted the results of the discussion and this is still wrong ... please correct me.

Here is the unit test asserting the behavior:

    /**
     * A reduce should fail with an IllegalArgumentException if done on an empty Observable.
     */
    @Test(expected = IllegalArgumentException.class)
    public void testReduceWithEmptyObservable() {
        Observable<Integer> observable = Observable.range(1, 0);
        observable.reduce(new Func2<Integer, Integer, Integer>() {

            @Override
            public Integer call(Integer t1, Integer t2) {
                return t1 + t2;
            }

        }).toBlockingObservable().forEach(new Action1<Integer>() {

            @Override
            public void call(Integer t1) {
                // do nothing ... we expect an exception instead
            }
        });

        fail("Expected an exception to be thrown");
    }

This fixes issue ReactiveX#423

The fix is based on this comment by @headinthebox: ReactiveX#423 (comment)
benjchristensen added a commit that referenced this pull request Nov 7, 2013
…bservable

BugFix: Reduce an empty observable
@benjchristensen benjchristensen merged commit 45f463d into ReactiveX:master Nov 7, 2013
@benjchristensen benjchristensen deleted the issue-423-reduce-empty-observable branch November 7, 2013 23:27
@cloudbees-pull-request-builder

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

rickbw pushed a commit to rickbw/RxJava that referenced this pull request Jan 9, 2014
…e-empty-observable

BugFix: Reduce an empty observable
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.

2 participants