-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Conversation
…when the Observable is empty
…irstOrDefaultTest and OperatorLastTest
RxJava-pull-requests #908 FAILURE |
RxJava-pull-requests #909 FAILURE |
RxJava-pull-requests #910 FAILURE |
RxJava-pull-requests #917 SUCCESS |
Thank you, @samueltardieu |
RxJava-pull-requests #918 SUCCESS |
@@ -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. |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
Waiting until Rx 0.18 since this is a breaking signature change (if dependent on the exception). |
This PR did the following work:
single
operatorfirst
,last
,single
to rxjava-scalaObservable
is empty,first
,last
,single
will throwNoSuchElementException
instead ofIllegalArgumentException
. It's more consistent with the Java Collection API, e.g., Deque.getFirst(), Deque.getLast(). This will break the current APIs.