Finish up work on NonEmptyList - #1231
Merged
Merged
Conversation
- Use toList instead of head::tail - Use tail ::: other.toList, instead of MonadCombine - Define apply method instead of using default paramter for tail - Use Nil instead of monad.empty - Simplify find and filter
- update this branch with latest changes from upstream master
This continues work started by @WarFox in typelevel#1120 (see [this comment](typelevel#1120 (comment))). At this point, I have left `OneAnd` in place. However, I think that after merging this we may want to delete it. In practice it's pretty awkward to use and sometimes prevents performant operations. See also typelevel#1089.
Current coverage is 89.86% (diff: 97.36%)@@ master #1231 diff @@
==========================================
Files 234 235 +1
Lines 3143 3208 +65
Methods 3089 3150 +61
Messages 0 0
Branches 51 55 +4
==========================================
+ Hits 2817 2883 +66
+ Misses 326 325 -1
Partials 0 0
|
Contributor
Author
|
It looks like I have some unit tests that I should add before this gets merged. I can probably add them tonight or tomorrow (Eastern time). I welcome code reviews before then. |
| * A data type which represents a non empty list of A, with | ||
| * single element (head) and optional structure (tail). | ||
| */ | ||
| final case class NonEmptyList[A](head: A, tail: List[A]) { |
Contributor
There was a problem hiding this comment.
what if we did something similar to NonEmptyVector and made this a value class around ::[A]? Then we would not need to allocate in some cases.
And also unit test improvements
Contributor
Author
|
Thanks for the great review, @johnynek! I've addressed many of your points. So far I haven't changed the representation from a case class with a |
|
|
||
| def toNonEmptyList[A](fa: F[A]): NonEmptyList[A] = | ||
| reduceRightTo(fa)(a => NonEmptyList(a, Nil)) { (a, lnel) => | ||
| lnel.map { case NonEmptyList(h, t) => NonEmptyList(a, h :: t) } |
Contributor
There was a problem hiding this comment.
should we add a :: nel to make a new NonEmptyList?
def ::(a: A): NonEmptyList[A] = NonEmptyList(a, head :: tail)
Contributor
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This continues work started by @WarFox in #1120 (see this comment).
At this point, I have left
OneAndin place. However, I think thatafter merging this we may want to delete it. In practice it's pretty
awkward to use and sometimes prevents performant operations. See also #1089.