-
Couldn't load subscription status.
- Fork 1.4k
Handle Heterogeneous Collections in ChunkBuilder #4295
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
| assertCompletes | ||
| }, | ||
| testM("chunks can be constructed from heterogeneous collections") { | ||
| check(Gen.listOf(Gen.oneOf(Gen.anyInt, Gen.anyString))) { as => |
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.
Would it make sense to add a generator for non-primitive types?
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.
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?
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.
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.
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.
Sounds good. Will add.
| try { | ||
| arrayBuilder += a | ||
| } catch { | ||
| case _: ClassCastException => |
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.
Probably the fastest way to handle this!
|
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)) |
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 blew up before, right?
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.
Yes.
Resolves #4288.