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

NonEmptyList work in progress [do-not-merge-yet] #1120

Closed
wants to merge 7 commits into from
Closed

NonEmptyList work in progress [do-not-merge-yet] #1120

wants to merge 7 commits into from

Conversation

WarFox
Copy link

@WarFox WarFox commented Jun 12, 2016

This is a work in progress branch for #1087 created during Hack the tower meet up in London on Saturday, 11 June 2016.

@ceedubs
Copy link
Contributor

ceedubs commented Jun 13, 2016

Thanks @WarFox -- this looks like a great start!

/**
* Return the head and tail into a single list
*/
def unwrap: List[A] = head :: tail
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think of us simply calling this toList?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the comments @ceedubs.. I'm learning!
I think it makes sense to call it toList. I was just trying to follow OneAnd.scala, thought it was a convention

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in OneAnd it's called unwrap since F is abstract so there's not a straightforward name to call it. Since we are fixed to List here, it's easier to come up with a good name :)

Copy link
Author

Choose a reason for hiding this comment

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

makes sense, I've pushed that change

* Append another NonEmptyList
*/
def combine(other: NonEmptyList[A]): NonEmptyList[A] =
NonEmptyList(head, MonadCombine[List].combineK(tail, other.head :: other.tail))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be simpler as:

NonEmptyList(head, tail ::: other.toList)

Copy link
Author

Choose a reason for hiding this comment

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

very much cleaner

@non
Copy link
Contributor

non commented Jun 13, 2016

Great job, thanks! This is looking really good. Feel free to remove the commented-out type aliases.

fa map f

def pure[A](x: A): NonEmptyList[F, A] =
NonEmptyList(x, monad.empty)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just use Nil instead of monad.empty here, since we know we are talking about List.

Copy link
Author

Choose a reason for hiding this comment

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

thanks for the detailed review :)
this is motivational
I shall do this changes tonight

*/
def filter(p: A => Boolean): List[A] = {
val rest = tail.filter(p)
if (p(head)) head :: rest else rest
Copy link
Contributor

@yilinwei yilinwei Jun 13, 2016

Choose a reason for hiding this comment

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

Would be tempted to go with (head :: tail).filter(p) which I think is toList.filter(p)

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually prefer being explicit and not creating a list when not necessary. I'll leave it to @WarFox to decide which way to go.

@yilinwei
Copy link
Contributor

Thanks for finishing the issue from hack the tower and putting it up for a pull request! 👍

new Monad[NonEmptyList[?]] {
override def map[A, B](fa: NonEmptyList[F, A])(f: A => B): NonEmptyList[F, B] =
fa map f

Copy link
Contributor

Choose a reason for hiding this comment

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

NonEmptyList should have only one type parameter, so this should be NonEmptyList[B] instead of NonEmptyList[F, B]. This should cause compilation errors.

Deepu Puthrote added 3 commits June 14, 2016 00:06
- 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
checkAll("Reducible[NonEmptyList[List, ?]]", SerializableTests.serializable(Reducible[NonEmptyList[List, ?]]))

implicit val iso = CartesianTests.Isomorphisms.invariant[NonEmptyList[ListWrapper, ?]](NonEmptyList.catsDataFunctorForNonEmptyList(ListWrapper.functor))

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need 2 iso's if the second one resolves.

@WarFox
Copy link
Author

WarFox commented Jun 17, 2016

Thanks guys. I've been busy this week with work and other things. Please allow me time to update this pull requests with these review comments, and please add more comments. I can't promise a time frame now.

- update this branch with latest changes from upstream master
@ceedubs
Copy link
Contributor

ceedubs commented Jul 23, 2016

Thanks for all of your work on this, @WarFox. I understand that you are busy. I'm hoping to get the NonEmptyList rework in before too long. Would you mind if I branch off of the commits that you have so far and then finish up the pending work?

ceedubs added a commit to ceedubs/cats that referenced this pull request Jul 25, 2016
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.
@WarFox
Copy link
Author

WarFox commented Jul 26, 2016

@ceedubs Hi Cody, I am sorry about this. I couldn't work on this due to various reasons. It is great of you to pickup the work. Appreciate it, thank you.

@ceedubs
Copy link
Contributor

ceedubs commented Jul 26, 2016

Hi @WarFox, it's no problem at all. Thanks for getting it off to a great start!

I'm going to close out this PR in favor of #1231 (which has these commits plus some more).

@ceedubs ceedubs closed this Jul 26, 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.

6 participants