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

Reimplement the 'single' operator #967

Merged
merged 8 commits into from
Apr 20, 2014
Merged

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Mar 17, 2014

This PR did the following work:

  • Reimplement the single operator
  • Add first, last, single to rxjava-scala
  • When the Observable is empty, first, last, single will throw NoSuchElementException instead of IllegalArgumentException. It's more consistent with the Java Collection API, e.g., Deque.getFirst(), Deque.getLast(). This will break the current APIs.

@cloudbees-pull-request-builder

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

@cloudbees-pull-request-builder

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

@cloudbees-pull-request-builder

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

@cloudbees-pull-request-builder

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

@zsxwing
Copy link
Member Author

zsxwing commented Mar 24, 2014

Thank you, @samueltardieu

@cloudbees-pull-request-builder

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

@@ -4545,12 +4545,12 @@ public final void onNext(T args) {

/**
* Returns an Observable that emits only the very first item emitted by the source Observable, or raises an
* {@code IllegalArgumentException} if the source Observable is empty.
Copy link
Member

Choose a reason for hiding this comment

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

It seems that it can still throw IllegalArgumentException if there are too many elements.

new IllegalArgumentException("Sequence contains too many elements")

So don't all of these Javadocs now need to include both IllegalArgumentException and NoSuchElementException?

Copy link
Member Author

Choose a reason for hiding this comment

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

An Observable which has more than one element is valid for first and last. These two operator just fetch the first or the last one from the Observable. Only single requires that the Observable must contain exactly one element.

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry, you do have both exceptions on some of the other methods where it applies. Nevermind!

@benjchristensen
Copy link
Member

Waiting until Rx 0.18 since this is a breaking signature change (if dependent on the exception).

@benjchristensen benjchristensen added this to the 0.18 milestone Mar 25, 2014
@benjchristensen benjchristensen merged commit 682f4bd into ReactiveX:master Apr 20, 2014
benjchristensen added a commit that referenced this pull request Apr 20, 2014
@zsxwing zsxwing deleted the single branch April 20, 2014 08:21
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.

None yet

4 participants