diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index 534d69ad933..1f3db47782b 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -1,5 +1,27 @@ package kotlin +/** + * Adds the specified [element] to this mutable collection. + */ +public fun MutableCollection.plusAssign(element: T) { + this.add(element) +} + +/** + * Adds all elements of the given [collection] to this mutable collection. + */ +public fun MutableCollection.plusAssign(collection: Iterable) { + this.addAll(collection) +} + +/** + * Adds all elements of the given [array] to this mutable collection. + */ +public fun MutableCollection.plusAssign(array: Array) { + this.addAll(array) +} + + /** * Adds all elements of the given [iterable] to this [MutableCollection]. */ diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index 1f7d5d4803b..e7ae486b969 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -233,6 +233,12 @@ class CollectionTest { l += arrayOf("cheese", "wine") assertEquals(listOf("cheese", "foo", "beer", "cheese", "wine"), l) assertTrue(l !== lOriginal) + + val ml = arrayListOf("cheese") + ml += "foo" + ml += listOf("beer") + ml += arrayOf("cheese", "wine") + assertEquals(l, ml) } test fun requireNoNulls() {