Also, is there any performance impact of using `fo...
# stdlib
g
Also, is there any performance impact of using
for (a in withIndex()) ...
rather than
var i = 0; for (a in iterable) { ...; a++ }
?
g
Yes, because withIndex creates IndexedValue for each item
I always use
forEachIndexed
instead of for + withIndex
g
I was wondering that, because it could happen to generate lazily rather than eagerly, which could make the impact negligible depending on the application.
g
IndexedValue generated lazily on each element, but if you traverse all elements will be generated + 1 object for each element
👍 1