Skip to content
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

Add Tuple#to_static_array #12930

Conversation

straight-shoota
Copy link
Member

Adds a method to convert a Tuple into an equivalent StaticArray.
The memory representation is similar but not necessarily identical, so this can't be a simple cast. StaticArray must contain type information which is already encoded by the position in a Tuple.

This conversion removes information, so it's rarely useful. One use case is for sorting, which just doesn't make sense for a Tuple. But turning it into a StaticArray, it can be sorted. A use case for that in stdlib is Channel.select_impl (#12756).
I think this method should be in stdlib because it can be generally useful, even though not very common.

spec/std/tuple_spec.cr Show resolved Hide resolved
src/tuple.cr Show resolved Hide resolved
Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

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

It makes sense for mono-typed tuples 👍

@beta-ziliani beta-ziliani added this to the 1.8.0 milestone Jan 13, 2023
@straight-shoota straight-shoota merged commit 0ce950d into crystal-lang:master Jan 14, 2023
@straight-shoota straight-shoota deleted the feature/tuple-to_static_array branch January 14, 2023 13:23
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants