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

StaticArray(T, N)#map returns an Array(T) #3354

Closed
Nephos opened this issue Sep 26, 2016 · 2 comments
Closed

StaticArray(T, N)#map returns an Array(T) #3354

Nephos opened this issue Sep 26, 2016 · 2 comments

Comments

@Nephos
Copy link
Contributor

Nephos commented Sep 26, 2016

Hello,

I wonder why a StaticArray.map returns an Array and not a StaticArray.

If you think it is better to returns a StaticArray, tell me I'll make a PR.

Regards,

@asterite
Copy link
Member

We could do this, yes. Right now map returns Array in all types except Tuple. There's a bit of tension because Array is the recommended container type to use, but I guess optimizing that for StaticArray and Slice would be a good idea (one can invoke to_a at the end if you need an array in the end).

@Nephos
Copy link
Contributor Author

Nephos commented Sep 26, 2016

I changed my mind, regarding how map should behave.
As it is still possible to use .map!, we can also do .dup.map! (optimizing way).

I don't think there is a need to change the behaviour of StaticArray(T, N).map (it means map cannot return something else than StaticArray(T, N))

I just added .map_with_index! which was missing.

  • no optimization problem as it is possible to use .dup.map!
  • no non-standard behavior as .map can returns something else than elements of type T (StaticArray(T, N))

Is it acceptable ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants