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

2.x: last() to return Single #4570

Merged
merged 1 commit into from
Sep 20, 2016
Merged

2.x: last() to return Single #4570

merged 1 commit into from
Sep 20, 2016

Conversation

akarnokd
Copy link
Member

This PR changes the return type of last() to Single<T> and updates the relevant locations.

Originally, it was implemented as takeLast(1).single() so to reduce impact, all other original uses now have this inlined.

@codecov-io
Copy link

Current coverage is 78.61% (diff: 77.50%)

Merging #4570 into 2.x will decrease coverage by 0.05%

@@                2.x      #4570   diff @@
==========================================
  Files           528        530     +2   
  Lines         35266      35337    +71   
  Methods           0          0          
  Messages          0          0          
  Branches       5474       5482     +8   
==========================================
+ Hits          27745      27781    +36   
- Misses         5541       5576    +35   
  Partials       1980       1980          

Powered by Codecov. Last update 85da0a8...0cdd458

inOrder.verify(observer, times(1)).onNext(3);
inOrder.verify(observer, times(1)).onComplete();
inOrder.verify(observer, times(1)).onSuccess(3);
// inOrder.verify(observer, times(1)).onComplete();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just remove all these?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will come in handy when the fuse-back is implemented (by copying these and restoring them to Observer/Subscriber). I'll delete them then

* error
* @see <a href="http://reactivex.io/documentation/operators/last.html">ReactiveX operators documentation: Last</a>
*/
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> last() {
return takeLast(1).single();
public final Single<T> last() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should return a Maybe<T> because the Flowable can be empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

The javadoc clearly states that an empty stream results in NoSuchElementException; but the former use of single() here is also a telltale sign.

Copy link
Contributor

Choose a reason for hiding this comment

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

An observable being empty is not exceptional and therefore shouldn't result in exceptions.

Copy link
Member Author

Choose a reason for hiding this comment

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

For this operator it is according to the 1.x docs:

https://github.com/ReactiveX/RxJava/blob/1.x/src/main/java/rx/Observable.java#L7398

Returns an Observable that emits the last item emitted by the source Observable or notifies observers of
a {@code NoSuchElementException} if the source Observable is empty.

2.x matches the 1.x behavior.

@@ -7659,8 +7659,8 @@ public final Disposable forEachWhile(final Predicate<? super T> onNext, Consumer
* @see <a href="http://reactivex.io/documentation/operators/last.html">ReactiveX operators documentation: Last</a>
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<T> last() {
return takeLast(1).single();
public final Single<T> last() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should return a Maybe<T> because the Flowable can be empty.

@abersnaze
Copy link
Contributor

P.S. I've pushed my current branch here. https://github.com/abersnaze/RxJava/tree/interop

@akarnokd
Copy link
Member Author

P.S. I've pushed my current branch here.

I see you didn't keep the original typed code to help with toFlowable(). Also I'm not fond of moving the blockingX because it adds an extra step/overhead.

I'd have to redo/reoptimize them anyways so don't really need that.

@akarnokd akarnokd merged commit 994d8fc into ReactiveX:2.x Sep 20, 2016
@akarnokd akarnokd deleted the LastSingle branch September 20, 2016 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants