-
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
2.x: dedicated reduce() op implementations #4885
Conversation
Current coverage is 95.58% (diff: 83.13%)@@ 2.x #4885 diff @@
==========================================
Files 581 586 +5
Lines 37212 37373 +161
Methods 0 0
Messages 0 0
Branches 5601 5616 +15
==========================================
+ Hits 35619 35722 +103
- Misses 654 683 +29
- Partials 939 968 +29
|
this.actual = actual; | ||
this.value = value; | ||
this.reducer = reducer; | ||
this.value = value; |
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.
2x this.value = value
? L64 & L66.
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.
Thanks, fixing...
RxJavaPlugins.onError(e); | ||
return; | ||
} | ||
value = null; |
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.
needs done=true
|
||
@Override | ||
public void onComplete() { | ||
T v = value; |
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.
check done
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.
I guess the real problem here is you don't have those done
related unit tests that I said I'd provide! I'll have a look at them soon.
|
||
@Override | ||
public void onNext(T value) { | ||
R v = this.value; |
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.
done
checks in this class?
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.
No need for separate done flag as this.value can't be initially null and becomes null if onError is called. Updated the PR with more checks.
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.
agreed
👍 with the qualifier that I'm not up on RxJava2/ReactiveStreams lifecycle in terms of subscription and disposal yet (that's for another day sorry!). |
This PR adds dedicated operator implementations to
Flowable.reduce(seed, reducer)
(returnsSingle
),Flowable.reduceWith(seedSupplier, reducer)
(returnsSingle
),Observable.reduce(reducer)
(returnsMaybe
),Observable.reduce(seed, reducer)
(returnsSingle
) andObservable.reduceWith(seedSupplier, reducer)
(returnsSingle
)instead of using
scan().takeLast(1)
(Flowable.reduce(reducer)
already had a dedicated operator).Comparison (Celeron 1005M, 4GB RAM, Windows 7 x64, Java 8u112, JMH 1.16):
The new
ReducePerf
benchmark does a simple sum over a list of integer values. Unfortunately, this creates a lot of garbage for longer sequences (plus the CPU/RAM is not really suited for such benchmarks; theflowMaybe
lines should be roughly the same since the code didn't change but there is a significant run-to-run variance).