-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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/Array improvements (map_with_index!) 2 #4456
StaticArray/Array improvements (map_with_index!) 2 #4456
Conversation
I don't understand, why is |
It should be |
Nevermind, I got confused. It's with |
It would be cool to have map_with_index! in the Array too |
Cool! Would you add |
After adding map_with_index! to StaticArray(T, I), it is good to have the same behaviour for Array(T). * Add Array(T).map_with_index!(&block) * Add a spec to test it
Anything else that should be added / changed ? |
No, looks good to me! Thank you! |
Since map! is actually implemented in Pointer, why not implement there the logic and let StaticArray forward the call as in map! Also, in Array#map_with_index! I think there should be no U, just T, since it is an inplace replacement. Forcing a T in the block will give a different and clearer error message. |
map! is defined first in Pointer, so map_with_index! should be. * move map_with_index! logic from Array/StaticArray to Pointer * fix map_with_index! parameters (block arguments / return) * add spec for Pointer.map_with_index!
You're right ! I fix that. |
In We shouldn't mix named block & yield. |
The block parameter is only used as documentation for the block types. Using block.call instead of yield will be uglier and perform much much worse. |
I see, for |
cf: #3356
(misusage of git on my side, I had to recreate a new PR, my bad)
Aims: have map_with_index! in the StaticArray