-
-
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
Implement NonEmptyList#Collect #1516
Implement NonEmptyList#Collect #1516
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1516 +/- ##
==========================================
+ Coverage 92.33% 92.33% +<.01%
==========================================
Files 247 247
Lines 3900 3903 +3
Branches 137 139 +2
==========================================
+ Hits 3601 3604 +3
Misses 299 299
Continue to review full report at Codecov.
|
I'm weakly -1 on adding methods which are identical to doing Methods that preserve nonemptiness are more interesting to me. |
What about returning: |
@xavier-fernandez, unless I am missing something, a |
I should close the PR? |
The main arguments that I can think of for having the |
On the other hand, |
Okay. On this argument I'm +1 on NonEmptyList.collect but not
NonEmptyVector.
…On Thu, Jan 5, 2017 at 23:58 Xavier Fernández Salas < ***@***.***> wrote:
NonEmptyList.collect will have a better performance than toList.collect...
On the other hand,NonEmptyVector.collect will not yield any performance
improvement.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1516 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEJdhyLQCQk9tS8ORePNXVRx52xQIFvks5rPhBKgaJpZM4Lbksu>
.
|
If |
I don't think so. Otherwise we'll have some other class justifying why we
should have yet another method.
Frankly, if consistency is the main driver I suggest we go back to only
adding methods if they preserve non-emptiness.
…On Sat, Jan 7, 2017 at 00:48 Xavier Fernández Salas < ***@***.***> wrote:
If NonEmptyList is having a collect method, it would not be better that
NonEmptyVector too, for consistency?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1516 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEJdvMOcd92tju5KLvjpL_hc-crW2fRks5rP21igaJpZM4Lbksu>
.
|
NonEmptyVector
and NonEmptyList
Modified the PR so the |
@@ -67,6 +67,30 @@ final case class NonEmptyList[+A](head: A, tail: List[A]) { | |||
} | |||
|
|||
/** | |||
* Builds a new collection by applying a partial function to |
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.
Should we say "Builds a new List
..." ?
* scala> nel.collect { | ||
* case v if v % 2 == 0 => "even" | ||
* case _ => "odd" | ||
* } |
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 should be :
/**
* ...
* scala> nel.collect {
* | case v if v % 2 == 0 => "even"
* | case _ => "odd"
* | }
* ...
*/
for the doctest to be generated correctly.
@peterneyens amend done :) |
👍 |
You need to use exactly
after a Right now the generated doctest is property("example at line 203: nel.collect { case v if v < 3 => v }") = org.scalacheck.Prop.secure {
sbtDoctestTypeEquals(nel.collect { case v if v < 3 => v })((nel.collect { case v if v < 3 => v }): scala.collection.immutable.List[Int])
val actual = sbtDoctestReplString(nel.collect { case v if v < 3 => v })
val expected = "List(1, 2)"
(actual == expected) :| s"'$actual' is not equal to '$expected'"
} So the last "odd" and "even" test is not checked. If you change it to /**
* scala> nel.collect {
* | case v if v % 2 == 0 => "even"
* | case _ => "odd"
* | }
*/ It will include this one as well : property("example at line 205: nel.collect { ...") = org.scalacheck.Prop.secure {
sbtDoctestTypeEquals(nel.collect {
case v if v % 2 == 0 => "even"
case _ => "odd"
})((nel.collect {
case v if v % 2 == 0 => "even"
case _ => "odd"
}): scala.collection.immutable.List[Int])
val actual = sbtDoctestReplString(nel.collect {
case v if v % 2 == 0 => "even"
case _ => "odd"
})
val expected = "List(odd, even, odd, even, odd)"
(actual == expected) :| s"'$actual' is not equal to '$expected'"
} It would be handy if |
@peterneyens will fix tomorrow morning, thank you :) |
Did an ammend fixing the DocTest generation :) |
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 for the doctest changes.
👍 merging with 2 sign-offs. |
NonEmptyVector
andNonEmptyList
.