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

Skip to content

Conversation

@ahoy-jon
Copy link
Contributor

@ahoy-jon ahoy-jon commented Apr 7, 2020

following discussion #3241

Copy link
Contributor

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

@ahoy-jon
Copy link
Contributor Author

ahoy-jon commented Apr 7, 2020

@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] 
}

@adamgfraser
Copy link
Contributor

@ahoy-jon Yes. It looks like if we only define both ++ variants on the implicit syntax and then the ++ variant on the NonEmpty subtype that works. Not sure if we can simplify any more.

@adamgfraser
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {})

@ahoy-jon
Copy link
Contributor Author

ahoy-jon commented Apr 7, 2020

<feelings>
@adamgfraser 🤪this technique was the initial PR!

I was actually fine with letting it go, and add a appendNonEmpty!
</feelings>

Thanks for the reviews.

About ZSink, I have modifications coming to improve the performance of +, once it is done, I will update ZSink.

@ahoy-jon ahoy-jon requested a review from adamgfraser April 7, 2020 03:23
Copy link
Contributor

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

@adamgfraser adamgfraser changed the title DO NOT MERGE, Fix ++(nonEmpty) on Chunk Fix ++(nonEmpty) on Chunk Apr 7, 2020
@adamgfraser adamgfraser merged commit 7bbf293 into zio:master Apr 7, 2020
@ahoy-jon ahoy-jon deleted the chunk-++ branch April 7, 2020 04:36
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.

2 participants