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

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Resolves #4288.

@adamgfraser adamgfraser requested a review from jdegoes October 7, 2020 23:08
assertCompletes
},
testM("chunks can be constructed from heterogeneous collections") {
check(Gen.listOf(Gen.oneOf(Gen.anyInt, Gen.anyString))) { as =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add a generator for non-primitive types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't String non-primitive in the sense that it is a subtype fo AnyRef as opposed to AnyVal? Or were you thinking of something different?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug we're fixing here existed because heterogeneous collections were not handled correctly. It's an implementation detail that this only happened in the presence of AnyVals, because there are no optimised implementations for AnyRefs. In the future we might for example introduce a Chunk optimised for Strings. Then we could run into the same type of bug again. I was thinking of generating Options, or case classes sharing trait.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Will add.

try {
arrayBuilder += a
} catch {
case _: ClassCastException =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the fastest way to handle this!

@jdegoes
Copy link
Member

jdegoes commented Oct 8, 2020

Love it! ❤️ The exception won't be thrown in the happy path, which will run at the same speed as before. 👍

},
testM("chunks can be constructed from heterogeneous collections") {
check(Gen.listOf(Gen.oneOf(Gen.anyInt, Gen.anyString, Gen.none))) { as =>
assert(Chunk.fromIterable(as).toList)(equalTo(as))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blew up before, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@adamgfraser adamgfraser merged commit d531787 into zio:master Oct 8, 2020
@adamgfraser adamgfraser deleted the 4288 branch October 13, 2020 23:32
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.

ClassCastException when calling ZStream.fromIterable provided with an Array[Any]

3 participants