Closed Kallekro closed 8 months ago
Thing is, that's not needed.
https://try.haxe.org/#62b71c31
var arr = ["haxe", "is", "for", "winners"];
for (idx => item in arr) {
trace(idx, item);
}
Works already, because of keyValueIterator()
that is present on Array and can be added to your types (also works through static extension).
See https://haxe.org/manual/lf-iterators.html#since-haxe-4.0.0
Oh really, that's kinda hilarious I didn't know that all this time!
But thanks for the heads up! Maybe the manual could show a small example of it being used on an array? Because I actually saw that documentation, but thought it only applied to maps.
Added custom iterator EnumerateIterator that returns both index and item when iterating.
I personally use this pattern very often, so wanted to share.