-
Couldn't load subscription status.
- Fork 1.4k
Fix ++(nonEmpty) on Chunk #3309
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
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.
Looks great! I think this or a slight variant of it will get us where we need to be.
|
@adamgfraser thanks for the review! changing it. Following #3241 (comment) it would work if we don't define : trait NonEmpty[A] {
def ++[A1 >: A](that: Chunk[A1]): NonEmptyChunk[A1]
} |
|
@ahoy-jon Yes. It looks like if we only define both |
|
I think we can get away with just defining the variant that takes a non-empty chunk in the implicit syntax class and leave everything else on the trait. |
|
|
||
| object Chunk { | ||
|
|
||
| implicit class ChunkOps[A](private val self: Chunk[A]) extends AnyVal { |
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.
Don't need the A1 type parameter here since A in ChunkOps is invariant.
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.
Not sure about that, it doesn't create compilation error in ZIO, but when with use subtyping, doesn't work.
trait A
trait B extends A
val x: Chunk[B] = Chunk.empty
//x: zio.Chunk[B] = Empty$()
x ++ (new A {})
<console>:28: error: overloaded method value ++ with alternatives:
(nonEmptyChunk: zio.NonEmptyChunk[B])zio.NonEmptyChunk[B] <and>
(chunk: zio.Chunk[B])zio.Chunk[B]
cannot be applied to (A)
x ++ (new A {})|
<feelings> I was actually fine with letting it go, and add a Thanks for the reviews. About |
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.
Looks great! Thanks for pushing on this. This is going to make it a lot nicer for users to work with nonempty chunks.
following discussion #3241