Provide extension to get mutable iterator from the mutable map
#KT-18992 Fixed
This commit is contained in:
@@ -298,8 +298,7 @@ public inline operator fun <K, V> Map<out K, V>.iterator(): Iterator<Map.Entry<K
|
||||
* Returns a [MutableIterator] over the mutable entries in the [MutableMap].
|
||||
*
|
||||
*/
|
||||
@JvmVersion
|
||||
@JvmName("mutableIterator")
|
||||
@kotlin.jvm.JvmName("mutableIterator")
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun <K, V> MutableMap<K, V>.iterator(): MutableIterator<MutableMap.MutableEntry<K, V>> = entries.iterator()
|
||||
|
||||
|
||||
@@ -97,6 +97,18 @@ class MapTest {
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
|
||||
}
|
||||
|
||||
@Test fun iterateAndMutate() {
|
||||
val map = mutableMapOf("beverage" to "beer", "location" to "Mells", "name" to "James")
|
||||
val it = map.iterator()
|
||||
for (e in it) {
|
||||
when (e.key) {
|
||||
"beverage" -> e.setValue("juice")
|
||||
"location" -> it.remove()
|
||||
}
|
||||
}
|
||||
assertEquals(mapOf("beverage" to "juice", "name" to "James"), map)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun onEach() {
|
||||
|
||||
Reference in New Issue
Block a user