https://kotlinlang.org logo
Title
g

gabrielfv

11/29/2018, 4:31 PM
Also, is there any performance impact of using
for (a in withIndex()) ...
rather than
var i = 0; for (a in iterable) { ...; a++ }
?
g

gildor

11/30/2018, 6:32 AM
Yes, because withIndex creates IndexedValue for each item
I always use
forEachIndexed
instead of for + withIndex
g

gabrielfv

11/30/2018, 3:31 PM
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

gildor

12/01/2018, 3:34 AM
IndexedValue generated lazily on each element, but if you traverse all elements will be generated + 1 object for each element
👍 1