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 ::: to NonEmptyList #1949

Merged
merged 5 commits into from
Nov 2, 2017
Merged

Add ::: to NonEmptyList #1949

merged 5 commits into from
Nov 2, 2017

Conversation

jcranky
Copy link
Contributor

@jcranky jcranky commented Oct 4, 2017

No description provided.

@codecov-io
Copy link

codecov-io commented Oct 4, 2017

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1949      +/-   ##
==========================================
+ Coverage   96.21%   96.21%   +<.01%     
==========================================
  Files         272      272              
  Lines        4627     4629       +2     
  Branches      124      119       -5     
==========================================
+ Hits         4452     4454       +2     
  Misses        175      175
Impacted Files Coverage Δ
core/src/main/scala/cats/data/NonEmptyVector.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/NonEmptyList.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/instances/map.scala 94.28% <0%> (-0.16%) ⬇️
core/src/main/scala/cats/Foldable.scala 100% <0%> (ø) ⬆️
core/src/main/scala/cats/data/Kleisli.scala 100% <0%> (ø) ⬆️

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 8d7b394...d8b501d. Read the comment docs.

@kailuowang
Copy link
Contributor

if you want, you can add a doctest to make the test coverage happy.

@@ -82,6 +82,9 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) {
def ::[AA >: A](a: AA): NonEmptyList[AA] =
NonEmptyList(a, head :: tail)

def :::[AA >: A](other: NonEmptyList[AA]): NonEmptyList[AA] =
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually to maintain symmetry, can we add ++: to NonEmptyVector as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure :)

@jcranky
Copy link
Contributor Author

jcranky commented Oct 5, 2017

Regarding doctest, where should I look at? I new to the cats codebase.

@LukaJCB
Copy link
Member

LukaJCB commented Oct 5, 2017

Doc test is a test in the Scaladoc right above the method itself :) our build pipeline we automatically check if the result is the same.

An example can be found in NonEmptyVector#filter :)

@@ -66,6 +66,11 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) extends AnyVal
def ++[AA >: A](other: Vector[AA]): NonEmptyVector[AA] = concat(other)

/**
* Append this NEV to another NEV, producing a new `NonEmptyVector`.
*/
def ++:[AA >: A](other: NonEmptyVector[AA]): NonEmptyVector[AA] = other.concatNev(this)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these be the other way around? ++ for two NEVs and ++: for an NEV and a Vector?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, I went with this #1838 (comment) - perhaps we should have both for both, since overloading is happening already anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is to mimic the API in Vector and List. Let's address #1838 first

@jcranky
Copy link
Contributor Author

jcranky commented Oct 5, 2017

@LukaJCB thanks for the explanation on doc test, I'll have a look

@jcranky
Copy link
Contributor Author

jcranky commented Oct 5, 2017

Tests added. This doctest thing is really cool, can you point me to somewhere where I can understand better how it works? Thanks!

@LukaJCB
Copy link
Member

LukaJCB commented Oct 5, 2017

Check out sbt-doctest :)

@jcranky
Copy link
Contributor Author

jcranky commented Oct 5, 2017

@LukaJCB thanks!

@jcranky
Copy link
Contributor Author

jcranky commented Oct 6, 2017

In the meanwhile, please let me know if I should do something else here :)

@jcranky
Copy link
Contributor Author

jcranky commented Oct 18, 2017

I guess we can now merge this as well? :)

* }}}
*/
def :::[AA >: A](other: NonEmptyList[AA]): NonEmptyList[AA] =
other.concat(this)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we use concatNel here instead? concat is deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@jcranky
Copy link
Contributor Author

jcranky commented Oct 18, 2017

@kailuowang done

@jcranky
Copy link
Contributor Author

jcranky commented Oct 24, 2017

@kailuowang anything else I should do here ? :)

@kailuowang
Copy link
Contributor

kailuowang commented Oct 24, 2017

The build is broken in scala doc generation

/home/travis/build/typelevel/cats/core/src/main/scala/cats/data/NonEmptyList.scala:102: The link target "concat" is ambiguous. Several members fit the target

Instead of linking it using [[]], just use concat should be fine.

@jcranky
Copy link
Contributor Author

jcranky commented Oct 24, 2017

@kailuowang ok, my bad, I was blind and didn't see the build was broken. Fixed :)

@kailuowang
Copy link
Contributor

@jcranky no worries at all. i probably should've pointed it out earlier.

@jcranky
Copy link
Contributor Author

jcranky commented Oct 25, 2017

@kailuowang now the build is ok 👍 🗡️

@LukaJCB LukaJCB added this to the 1.0.0 milestone Nov 1, 2017
@tpolecat
Copy link
Member

tpolecat commented Nov 1, 2017

It's not obvious to me what the use case is here. a ::: b/a ++: b are always equivalent to a ++ b right?

@jcranky
Copy link
Contributor Author

jcranky commented Nov 2, 2017

@tpolecat my main reasoning for this was to keep symmetry with List. Plus, ++ / ++: are not there, or are they?

@jcranky
Copy link
Contributor Author

jcranky commented Nov 2, 2017

(I found myself using .toList a few times just to use :::)

@kailuowang
Copy link
Contributor

@tpolecat ++ was added to concat with List rather than NEL, for maintaining compatibility we didn't want to change that.

Copy link
Member

@tpolecat tpolecat left a comment

Choose a reason for hiding this comment

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

Ok, seems fine. 👍

@kailuowang kailuowang merged commit 9912a8e into typelevel:master Nov 2, 2017
@jcranky
Copy link
Contributor Author

jcranky commented Nov 3, 2017

thanks :)

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.

5 participants