Skip to content

Finish up work on NonEmptyList - #1231

Merged
adelbertc merged 13 commits into
typelevel:masterfrom
ceedubs:nel
Jul 27, 2016
Merged

adelbertc merged 13 commits into
typelevel:masterfrom
ceedubs:nel

Conversation

@ceedubs

@ceedubs ceedubs commented Jul 25, 2016

Copy link
Copy Markdown
Contributor

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

codecov-io commented Jul 25, 2016 •

Copy link
Copy Markdown

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

ceedubs commented Jul 25, 2016

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

Copy link
Copy Markdown
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

ceedubs commented Jul 26, 2016

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


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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

👍

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