-
Couldn't load subscription status.
- Fork 1.4k
Improve Support for NonEmptyChunk #3374
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
Conversation
| case Chunk.Empty => Chunk.single(a) | ||
| case ne: NonEmptyChunk[A] => Chunk.concat(ne, Chunk.single(a)) | ||
| } | ||
| final def +[A1 >: A](a: A1): Chunk[A1] = |
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.
this could still return NonEmptyChunk
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.
We could but there is potentially a little extra overhead in creating the NonEmptyChunk which I thought you might not want if you were doing repeated appends and were doing high performance stuff where you didn't care about whether it was empty or not (e.g. you're just calling foreach on it). So right now you kind of stay in the Chunk world unless you explicitly go to the NonEmptyChunk world, and once you're there we preserve that information whenever possible. But we could definitely change as you suggest.
| * `NonEmptyChunk`. Operations on `NonEmptyChunk` which could potentially | ||
| * return an empty chunk will return a `Chunk` instead. | ||
| */ | ||
| final class NonEmptyChunk[+A] private (private val chunk: Chunk[A]) { self => |
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.
Could we make this a value class?
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.
Potentially. The issue there is that then it is the same class at runtime as Chunk so methods that have overloads for Chunk and NonEmptyChunk like foreach cause compiler errors. We could possibly resolve by adding a dummy parameter to them.
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.
Feels much cleaner and I like the symmetry with List / NonEmptyList.
Resolves #3357.