I don’t understand what do you mean by in-place? Do you mean
inline? The stdlib version is a
inline function so I don’t see the difference.
Ok, now I understand what you mean. You want a
mapIndexed which modifies the original list/array/etc.
I think I might support this addition. There are reasons for and against it.
- Updating a list multiple other places reference without having to share update the references of the other places.
- This would probably be more memory efficient, especially for long lists, as you no longer need to hold 2 copies in memory
- If the original list is no longer needed this would be less work for the garbage collector ( so minor performance increase)?
- Could lead to misunderstandings in comparison to
map as people who are coming from languages without functional programing aspects might not be used to the terminology and therefor lead to bugs which might be very hard to find
The more I think about it the more I like adding this to the std-lib. I would be interested if there are any other reasons for or against it as I can’t think of them right now.