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

Observable.collect improvement to avoid double evaluation (#742) #743

Merged
merged 1 commit into from Oct 18, 2018

Conversation

Projects
None yet
2 participants
@jfwilson
Contributor

jfwilson commented Oct 14, 2018

Avoid double evaluation of PartialFunctions in CollectOperator.

I have replaced .isDefinedAt and .apply with a single call to .applyOrElse in the same way as done in standard scala collection collect implementations. This has the benefit that any guard or unapply logic within the partial function is only evaluated once.

This does require a small amount of casting (of a magic fallback value) to work. Alternatively could use PartialFunction.lift to return an Option[B], but I'm less keen on this because in many cases this would require allocating an extra Some(_) on each element and the type casting is still happening (but is done inside PartialFunction.Lifted instead).

Observable.collect improvement (#742)
Avoid double evaluation of PartialFunctions in CollectOperator
@codecov

This comment has been minimized.

codecov bot commented Oct 14, 2018

Codecov Report

Merging #743 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
- Coverage   90.51%   90.48%   -0.03%     
==========================================
  Files         398      398              
  Lines       11256    11259       +3     
  Branches     2077     2088      +11     
==========================================
  Hits        10188    10188              
- Misses       1068     1071       +3

@alexandru alexandru merged commit 0b1de1d into monix:master Oct 18, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@alexandru

This comment has been minimized.

Member

alexandru commented Oct 18, 2018

Thanks @jfwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment