2 ms·
> How often do you need to have both the element and its index? I'd say it's not the majority of cases. And now you have to type "_," in 99% loops. Needing eit
by masklinn 4y ago
> How often do you need to have both the element and its index? I'd say it's not the majority of cases. And now you have to type "_," in 99% loops.
Needing either the index or both is likely a lot more common in Go than in other languages owing to the lack of any sort of iterator or composition. So e.g. any sort of zipping or in-place mapping requires the index.
> Although, that would only in practice affect integer lists (i.e. code silently compiles).
Not so. It would also affect strings (runes are integers), as well as maps with the same key and value types. Plus it could affect every other case depending how the item is used.
- kgeist 4y ago>Needing either the index or both is likely a lot more common in Go than in other languages owing to the lack of any sort of iterator or composition In our codebase, there's very few instances of needing the index. Usually you just want to iterate over a list and apply some function(s) to the elements or add them to another list.