-
Notifications
You must be signed in to change notification settings - Fork 99
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
Immutable, singly-linked list implementation. #5
Conversation
This code is very similar to scala.List, with a few key differences: 1. It does not expose any "unsafe" methods. 2. It is invariant, whereas scala.List is covariant. 3. It uses subtyping to differentiate non-emptiness. 4. It provides Cats type class instances. 5. It does not currently provide a fast (mutable) builder. The types defined here are as follows: - Lst[A] represents a list of zero-or-more elements. - Nel[A] represents a list of one-or-more elements. - El[A] represents an empty list (exactly zero elements). (Every Lst[A] is either a Nel[A] or an El[A].) While it does not (yet) provide every single Scala collection method, it provides a decent number of them. Type class instances are provided for both Lst and Nel (for example, Nel has a Comonad instance, whereas Lst only has a CoflatMap instance).
For what it's worth, I think the names I think it's relatively important that at least EDIT: Also needs tests and scaladoc comments of course! |
Current coverage is
|
I'm going to write up some tests for this, but I like the idea, It is one I have played around with in the past. These names aren't terrible. "a list is either a nel or an el" has a nice poetic meter :). I'd also be happy with Cons and End instead of Nel and El I am able to convince myself that I would be okay with calling the trait |
case El() => b | ||
} | ||
|
||
final def getNonEmpty: Option[Nel[A]] = |
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.
toNel
would seem more natural to me
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.
That's a good idea, I'll change it.
adapt to -Yno-imports
bring topic/nel-list up to date with refactor
I'm super busy this week, and there is no reason for this thing to sit out on a PR, I'm going to just go ahead and merge for now, When I'm above water again, I'll try to convert the things in Dequeue to Lst to see how natural that feels and add the rest of the law checking. |
Immutable, singly-linked list implementation.
This code is very similar to scala.List, with a few key differences:
The types defined here are as follows:
(Every Lst[A] is either a Nel[A] or an El[A].)
While it does not (yet) provide every single Scala collection
method, it provides a decent number of them. Type class instances
are provided for both Lst and Nel (for example, Nel has a Comonad
instance, whereas Lst only has a CoflatMap instance).