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

Finish up work on NonEmptyList #1231

Merged
merged 13 commits into from
Jul 27, 2016
Merged

Finish up work on NonEmptyList #1231

merged 13 commits into from
Jul 27, 2016

Conversation

ceedubs
Copy link
Contributor

@ceedubs ceedubs commented Jul 25, 2016

This continues work started by @WarFox in #1120 (see this 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 #1089.

Deepu Puthrote and others added 9 commits June 11, 2016 16:16
- 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.
@codecov-io
Copy link

codecov-io commented Jul 25, 2016

Current coverage is 89.86% (diff: 97.36%)

Merging #1231 into master will increase coverage by 0.24%

@@             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          

Sunburst

Powered by Codecov. Last update 0965afe...cfdd085

@ceedubs
Copy link
Contributor Author

ceedubs commented Jul 25, 2016

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]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@ceedubs
Copy link
Contributor Author

ceedubs commented Jul 26, 2016

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 head and a tail, because there didn't seem to be a strong inclination there. I'm open to ideas.

@@ -113,6 +115,11 @@ import simulacrum.typeclass
def sequence1_[G[_], A](fga: F[G[A]])(implicit G: Apply[G]): G[Unit] =
G.map(reduceLeft(fga)((x, y) => G.map2(x, y)((_, b) => b)))(_ => ())

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) }
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add a :: nel to make a new NonEmptyList?

def ::(a: A): NonEmptyList[A] = NonEmptyList(a, head :: tail)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@kailuowang
Copy link
Contributor

👍

@johnynek
Copy link
Contributor

This looks great! Thanks! 👍

@travisbrown
Copy link
Contributor

👍 from me! Looking forward to this.

@adelbertc
Copy link
Contributor

Nice! LGTM 👍

@adelbertc adelbertc merged commit 3ab307b into typelevel:master Jul 27, 2016
@stew stew removed the in progress label Jul 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants