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

Add zipWith to NonEmptyList and NonEmptyVector #1885

Merged
merged 1 commit into from
Sep 1, 2017

Conversation

LukaJCB
Copy link
Member

@LukaJCB LukaJCB commented Sep 1, 2017

Should resolve #1870

@codecov-io
Copy link

codecov-io commented Sep 1, 2017

Codecov Report

Merging #1885 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
core/src/main/scala/cats/data/NonEmptyList.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/NonEmptyVector.scala 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d85cc86...5abdb48. Read the comment docs.

* }}}
*/
def zipWith[B, C](b: NonEmptyVector[B])(f: (A, B) => C): NonEmptyVector[C] =
NonEmptyVector.fromVectorUnsafe((toVector, b.toVector).zipped.map(f))
Copy link
Contributor

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?

Copy link
Member Author

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh nice.

@johnynek
Copy link
Contributor

johnynek commented Sep 1, 2017

👍

@kailuowang kailuowang merged commit e8891b1 into typelevel:master Sep 1, 2017
@LukaJCB LukaJCB deleted the zip-with branch September 1, 2017 22:50
@LukaJCB LukaJCB mentioned this pull request Sep 2, 2017
@kailuowang kailuowang added this to the 1.0.0-RC1 milestone Oct 13, 2017
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.

Add zipWith to NonEmptyList
4 participants