-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add zipWith to NonEmptyList and NonEmptyVector #1885
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1885 +/- ##
==========================================
+ Coverage 94.97% 94.97% +<.01%
==========================================
Files 241 241
Lines 4199 4202 +3
Branches 106 112 +6
==========================================
+ Hits 3988 3991 +3
Misses 211 211
Continue to review full report at Codecov.
|
* }}} | ||
*/ | ||
def zipWith[B, C](b: NonEmptyVector[B])(f: (A, B) => C): NonEmptyVector[C] = | ||
NonEmptyVector.fromVectorUnsafe((toVector, b.toVector).zipped.map(f)) |
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 think this will be maybe faster if we do:
toVector.iterator.zip(b.toVector.iterator).map(f).toVector
I think the current code has to allocate a NonEmptyVector after zipped
and then another one after map
.
But I'm just guessing since I don't know this tuple enrichment. Can you comment as to why this is incorrect if I am wrong?
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.
Yes of course! I'm on my phone right now, but if you look at the source for zipped https://github.com/scala/scala/tree/v2.12.3/src/library/scala/runtime/Tuple2Zipped.scala#L1 you'll see that it does not actually iterate over either of the vectors until you call map or any of the other methods :)
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.
ahh nice.
👍 |
Should resolve #1870