platform-collections icon indicating copy to clipboard operation
platform-collections copied to clipboard

Only snapshot contents when mutating `iterator()`

Open JakeWharton opened this issue 2 years ago • 1 comments

~operator fun iterator(): Iterator<..> for the language-level for-each. And fun mutableIterator(): MutableIterator<..> for the manual loop-and-remove case.~

JakeWharton avatar Mar 06 '23 05:03 JakeWharton

Better idea: detect the first call to remove() and perform the defensive copy then. This only affects Darwin, as JVM and JS support removal while iterating.

JakeWharton avatar Mar 07 '23 03:03 JakeWharton