Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Resolves #3357.

case Chunk.Empty => Chunk.single(a)
case ne: NonEmptyChunk[A] => Chunk.concat(ne, Chunk.single(a))
}
final def +[A1 >: A](a: A1): Chunk[A1] =
Copy link
Member

@mschuwalow mschuwalow Apr 15, 2020

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

Copy link
Contributor Author

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.

@adamgfraser adamgfraser requested a review from jdegoes April 15, 2020 12:20
* `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 =>
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@jdegoes jdegoes left a 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.

@jdegoes jdegoes merged commit bc77e9e into zio:master Apr 15, 2020
@adamgfraser adamgfraser deleted the nonemptychunk branch April 22, 2020 01:55
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.

Improve Support for NonEmptyChunk

3 participants