diff --git a/js/js.libraries/src/core/kotlin_special.kt b/js/js.libraries/src/core/kotlin_special.kt index 2b392eb4180..4cd0232763c 100644 --- a/js/js.libraries/src/core/kotlin_special.kt +++ b/js/js.libraries/src/core/kotlin_special.kt @@ -281,141 +281,6 @@ public inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArr return this.asDynamic().slice(fromIndex, toIndex) } -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun Array.plus(array: Array): Array { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun BooleanArray.plus(array: BooleanArray): BooleanArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun ByteArray.plus(array: ByteArray): ByteArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun CharArray.plus(array: CharArray): CharArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun DoubleArray.plus(array: DoubleArray): DoubleArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun FloatArray.plus(array: FloatArray): FloatArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun IntArray.plus(array: IntArray): IntArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun LongArray.plus(array: LongArray): LongArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@Suppress("NOTHING_TO_INLINE") -public inline fun ShortArray.plus(array: ShortArray): ShortArray { - return this.asDynamic().concat(array) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun Array.plus(collection: Collection): Array { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun BooleanArray.plus(collection: Collection): BooleanArray { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun ByteArray.plus(collection: Collection): ByteArray { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun CharArray.plus(collection: Collection): CharArray { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun DoubleArray.plus(collection: Collection): DoubleArray { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun FloatArray.plus(collection: Collection): FloatArray { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun IntArray.plus(collection: Collection): IntArray { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun LongArray.plus(collection: Collection): LongArray { - return arrayPlusCollection(this, collection) -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -public fun ShortArray.plus(collection: Collection): ShortArray { - return arrayPlusCollection(this, collection) -} - /** * Returns an array containing all elements of the original array and then the given [element]. */ @@ -488,6 +353,141 @@ public inline fun ShortArray.plus(element: Short): ShortArray { return this.asDynamic().concat(arrayOf(element)) } +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun Array.plus(elements: Collection): Array { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun BooleanArray.plus(elements: Collection): BooleanArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun ByteArray.plus(elements: Collection): ByteArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun CharArray.plus(elements: Collection): CharArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun DoubleArray.plus(elements: Collection): DoubleArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun FloatArray.plus(elements: Collection): FloatArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun IntArray.plus(elements: Collection): IntArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun LongArray.plus(elements: Collection): LongArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public fun ShortArray.plus(elements: Collection): ShortArray { + return arrayPlusCollection(this, elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun Array.plus(elements: Array): Array { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun BooleanArray.plus(elements: BooleanArray): BooleanArray { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun ByteArray.plus(elements: ByteArray): ByteArray { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun CharArray.plus(elements: CharArray): CharArray { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun DoubleArray.plus(elements: DoubleArray): DoubleArray { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun FloatArray.plus(elements: FloatArray): FloatArray { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun IntArray.plus(elements: IntArray): IntArray { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun LongArray.plus(elements: LongArray): LongArray { + return this.asDynamic().concat(elements) +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@Suppress("NOTHING_TO_INLINE") +public inline fun ShortArray.plus(elements: ShortArray): ShortArray { + return this.asDynamic().concat(elements) +} + /** * Sorts the array in-place. */ diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index 4e931f482fd..d3fa33036c1 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -11150,213 +11150,6 @@ public fun , R> Array<*>.filterIsInstanceTo(destinat return destination } -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun BooleanArray.plus(array: BooleanArray): BooleanArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun ByteArray.plus(array: ByteArray): ByteArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun CharArray.plus(array: CharArray): CharArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun DoubleArray.plus(array: DoubleArray): DoubleArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun FloatArray.plus(array: FloatArray): FloatArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun IntArray.plus(array: IntArray): IntArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun LongArray.plus(array: LongArray): LongArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun ShortArray.plus(array: ShortArray): ShortArray { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [array]. - */ -@kotlin.jvm.JvmVersion -public operator fun Array.plus(array: Array): Array { - val thisSize = size - val arraySize = array.size - val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun BooleanArray.plus(collection: Collection): BooleanArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun ByteArray.plus(collection: Collection): ByteArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun CharArray.plus(collection: Collection): CharArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun DoubleArray.plus(collection: Collection): DoubleArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun FloatArray.plus(collection: Collection): FloatArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun IntArray.plus(collection: Collection): IntArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun LongArray.plus(collection: Collection): LongArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun ShortArray.plus(collection: Collection): ShortArray { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [collection]. - */ -@kotlin.jvm.JvmVersion -public operator fun Array.plus(collection: Collection): Array { - var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element - return result -} - /** * Returns an array containing all elements of the original array and then the given [element]. */ @@ -11456,6 +11249,213 @@ public operator fun Array.plus(element: T): Array { return result } +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun BooleanArray.plus(elements: Collection): BooleanArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun ByteArray.plus(elements: Collection): ByteArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun CharArray.plus(elements: Collection): CharArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun DoubleArray.plus(elements: Collection): DoubleArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun FloatArray.plus(elements: Collection): FloatArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun IntArray.plus(elements: Collection): IntArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun LongArray.plus(elements: Collection): LongArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun ShortArray.plus(elements: Collection): ShortArray { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +@kotlin.jvm.JvmVersion +public operator fun Array.plus(elements: Collection): Array { + var index = size + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun ByteArray.plus(elements: ByteArray): ByteArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun CharArray.plus(elements: CharArray): CharArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun FloatArray.plus(elements: FloatArray): FloatArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun IntArray.plus(elements: IntArray): IntArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun LongArray.plus(elements: LongArray): LongArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun ShortArray.plus(elements: ShortArray): ShortArray { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +@kotlin.jvm.JvmVersion +public operator fun Array.plus(elements: Array): Array { + val thisSize = size + val arraySize = elements.size + val result = Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + /** * Sorts the array in-place. */ diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index d7544b8f42b..b19c5f00a25 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -1493,25 +1493,6 @@ public fun List.requireNoNulls(): List { return this as List } -/** - * Returns a list containing all elements of the original collection except the elements contained in the given [array]. - */ -public operator fun Iterable.minus(array: Array): List { - if (array.isEmpty()) return this.toList() - val other = array.toHashSet() - return this.filterNot { it in other } -} - -/** - * Returns a list containing all elements of the original collection except the elements contained in the given [collection]. - */ -public operator fun Iterable.minus(collection: Iterable): List { - val other = collection.convertToSetForSetOperationWith(this) - if (other.isEmpty()) - return this.toList() - return this.filterNot { it in other } -} - /** * Returns a list containing all elements of the original collection without the first occurrence of the given [element]. */ @@ -1522,10 +1503,29 @@ public operator fun Iterable.minus(element: T): List { } /** - * Returns a list containing all elements of the original collection except the elements contained in the given [sequence]. + * Returns a list containing all elements of the original collection except the elements contained in the given [elements] array. */ -public operator fun Iterable.minus(sequence: Sequence): List { - val other = sequence.toHashSet() +public operator fun Iterable.minus(elements: Array): List { + if (elements.isEmpty()) return this.toList() + val other = elements.toHashSet() + return this.filterNot { it in other } +} + +/** + * Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection. + */ +public operator fun Iterable.minus(elements: Iterable): List { + val other = elements.convertToSetForSetOperationWith(this) + if (other.isEmpty()) + return this.toList() + return this.filterNot { it in other } +} + +/** + * Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence. + */ +public operator fun Iterable.minus(elements: Sequence): List { + val other = elements.toHashSet() if (other.isEmpty()) return this.toList() return this.filterNot { it in other } @@ -1549,54 +1549,6 @@ public inline fun Iterable.partition(predicate: (T) -> Boolean): Pair Collection.plus(array: Array): List { - val result = ArrayList(this.size + array.size) - result.addAll(this) - result.addAll(array) - return result -} - -/** - * Returns a list containing all elements of the original collection and then all elements of the given [array]. - */ -public operator fun Iterable.plus(array: Array): List { - if (this is Collection) return this.plus(array) - val result = ArrayList() - result.addAll(this) - result.addAll(array) - return result -} - -/** - * Returns a list containing all elements of the original collection and then all elements of the given [collection]. - */ -public operator fun Collection.plus(collection: Iterable): List { - if (collection is Collection) { - val result = ArrayList(this.size + collection.size) - result.addAll(this) - result.addAll(collection) - return result - } else { - val result = ArrayList(this) - result.addAll(collection) - return result - } -} - -/** - * Returns a list containing all elements of the original collection and then all elements of the given [collection]. - */ -public operator fun Iterable.plus(collection: Iterable): List { - if (this is Collection) return this.plus(collection) - val result = ArrayList() - result.addAll(this) - result.addAll(collection) - return result -} - /** * Returns a list containing all elements of the original collection and then the given [element]. */ @@ -1619,22 +1571,70 @@ public operator fun Iterable.plus(element: T): List { } /** - * Returns a list containing all elements of the original collection and then all elements of the given [sequence]. + * Returns a list containing all elements of the original collection and then all elements of the given [elements] array. */ -public operator fun Collection.plus(sequence: Sequence): List { - val result = ArrayList(this.size + 10) +public operator fun Collection.plus(elements: Array): List { + val result = ArrayList(this.size + elements.size) result.addAll(this) - result.addAll(sequence) + result.addAll(elements) return result } /** - * Returns a list containing all elements of the original collection and then all elements of the given [sequence]. + * Returns a list containing all elements of the original collection and then all elements of the given [elements] array. */ -public operator fun Iterable.plus(sequence: Sequence): List { +public operator fun Iterable.plus(elements: Array): List { + if (this is Collection) return this.plus(elements) val result = ArrayList() result.addAll(this) - result.addAll(sequence) + result.addAll(elements) + return result +} + +/** + * Returns a list containing all elements of the original collection and then all elements of the given [elements] collection. + */ +public operator fun Collection.plus(elements: Iterable): List { + if (elements is Collection) { + val result = ArrayList(this.size + elements.size) + result.addAll(this) + result.addAll(elements) + return result + } else { + val result = ArrayList(this) + result.addAll(elements) + return result + } +} + +/** + * Returns a list containing all elements of the original collection and then all elements of the given [elements] collection. + */ +public operator fun Iterable.plus(elements: Iterable): List { + if (this is Collection) return this.plus(elements) + val result = ArrayList() + result.addAll(this) + result.addAll(elements) + return result +} + +/** + * Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence. + */ +public operator fun Collection.plus(elements: Sequence): List { + val result = ArrayList(this.size + 10) + result.addAll(this) + result.addAll(elements) + return result +} + +/** + * Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence. + */ +public operator fun Iterable.plus(elements: Sequence): List { + val result = ArrayList() + result.addAll(this) + result.addAll(elements) return result } diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index 88443ba1534..ecbb65129a9 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -903,38 +903,6 @@ public fun Sequence.requireNoNulls(): Sequence { return map { it ?: throw IllegalArgumentException("null element found in $this.") } } -/** - * Returns a sequence containing all elements of original sequence except the elements contained in the given [array]. - * Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from - * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. - */ -public operator fun Sequence.minus(array: Array): Sequence { - if (array.isEmpty()) return this - return object: Sequence { - override fun iterator(): Iterator { - val other = array.toHashSet() - return this@minus.filterNot { it in other }.iterator() - } - } -} - -/** - * Returns a sequence containing all elements of original sequence except the elements contained in the given [collection]. - * Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from - * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. - */ -public operator fun Sequence.minus(collection: Iterable): Sequence { - return object: Sequence { - override fun iterator(): Iterator { - val other = collection.convertToSetForSetOperation() - if (other.isEmpty()) - return this@minus.iterator() - else - return this@minus.filterNot { it in other }.iterator() - } - } -} - /** * Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element]. */ @@ -948,14 +916,46 @@ public operator fun Sequence.minus(element: T): Sequence { } /** - * Returns a sequence containing all elements of original sequence except the elements contained in the given [sequence]. + * Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] array. + * Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from + * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. + */ +public operator fun Sequence.minus(elements: Array): Sequence { + if (elements.isEmpty()) return this + return object: Sequence { + override fun iterator(): Iterator { + val other = elements.toHashSet() + return this@minus.filterNot { it in other }.iterator() + } + } +} + +/** + * Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] collection. + * Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from + * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. + */ +public operator fun Sequence.minus(elements: Iterable): Sequence { + return object: Sequence { + override fun iterator(): Iterator { + val other = elements.convertToSetForSetOperation() + if (other.isEmpty()) + return this@minus.iterator() + else + return this@minus.filterNot { it in other }.iterator() + } + } +} + +/** + * Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] sequence. * Note that the source sequence and the sequence being subtracted are iterated only when an `iterator` is requested from * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. */ -public operator fun Sequence.minus(sequence: Sequence): Sequence { +public operator fun Sequence.minus(elements: Sequence): Sequence { return object: Sequence { override fun iterator(): Iterator { - val other = sequence.toHashSet() + val other = elements.toHashSet() if (other.isEmpty()) return this@minus.iterator() else @@ -982,24 +982,6 @@ public inline fun Sequence.partition(predicate: (T) -> Boolean): Pair Sequence.plus(array: Array): Sequence { - return this.plus(array.asList()) -} - -/** - * Returns a sequence containing all elements of original sequence and then all elements of the given [collection]. - * Note that the source sequence and the collection being added are iterated only when an `iterator` is requested from - * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. - */ -public operator fun Sequence.plus(collection: Iterable): Sequence { - return sequenceOf(this, collection.asSequence()).flatten() -} - /** * Returns a sequence containing all elements of the original sequence and then the given [element]. */ @@ -1008,12 +990,30 @@ public operator fun Sequence.plus(element: T): Sequence { } /** - * Returns a sequence containing all elements of original sequence and then all elements of the given [sequence]. + * Returns a sequence containing all elements of original sequence and then all elements of the given [elements] array. + * Note that the source sequence and the array being added are iterated only when an `iterator` is requested from + * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. + */ +public operator fun Sequence.plus(elements: Array): Sequence { + return this.plus(elements.asList()) +} + +/** + * Returns a sequence containing all elements of original sequence and then all elements of the given [elements] collection. + * Note that the source sequence and the collection being added are iterated only when an `iterator` is requested from + * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. + */ +public operator fun Sequence.plus(elements: Iterable): Sequence { + return sequenceOf(this, elements.asSequence()).flatten() +} + +/** + * Returns a sequence containing all elements of original sequence and then all elements of the given [elements] sequence. * Note that the source sequence and the sequence being added are iterated only when an `iterator` is requested from * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. */ -public operator fun Sequence.plus(sequence: Sequence): Sequence { - return sequenceOf(this, sequence).flatten() +public operator fun Sequence.plus(elements: Sequence): Sequence { + return sequenceOf(this, elements).flatten() } /** diff --git a/libraries/stdlib/src/generated/_Sets.kt b/libraries/stdlib/src/generated/_Sets.kt index 5bd60cb49b3..cab5f5563ad 100644 --- a/libraries/stdlib/src/generated/_Sets.kt +++ b/libraries/stdlib/src/generated/_Sets.kt @@ -13,19 +13,28 @@ import java.util.* import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js /** - * Returns a set containing all elements of the original set except the elements contained in the given [array]. + * Returns a set containing all elements of the original set except the given [element]. */ -public operator fun Set.minus(array: Array): Set { +public operator fun Set.minus(element: T): Set { + val result = LinkedHashSet(mapCapacity(size)) + var removed = false + return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true } +} + +/** + * Returns a set containing all elements of the original set except the elements contained in the given [elements] array. + */ +public operator fun Set.minus(elements: Array): Set { val result = LinkedHashSet(this) - result.removeAll(array) + result.removeAll(elements) return result } /** - * Returns a set containing all elements of the original set except the elements contained in the given [collection]. + * Returns a set containing all elements of the original set except the elements contained in the given [elements] collection. */ -public operator fun Set.minus(collection: Iterable): Set { - val other = collection.convertToSetForSetOperationWith(this) +public operator fun Set.minus(elements: Iterable): Set { + val other = elements.convertToSetForSetOperationWith(this) if (other.isEmpty()) return this.toSet() if (other is Set) @@ -36,40 +45,11 @@ public operator fun Set.minus(collection: Iterable): Set { } /** - * Returns a set containing all elements of the original set except the given [element]. + * Returns a set containing all elements of the original set except the elements contained in the given [elements] sequence. */ -public operator fun Set.minus(element: T): Set { - val result = LinkedHashSet(mapCapacity(size)) - var removed = false - return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true } -} - -/** - * Returns a set containing all elements of the original set except the elements contained in the given [sequence]. - */ -public operator fun Set.minus(sequence: Sequence): Set { +public operator fun Set.minus(elements: Sequence): Set { val result = LinkedHashSet(this) - result.removeAll(sequence) - return result -} - -/** - * Returns a set containing all elements both of the original set and the given [array]. - */ -public operator fun Set.plus(array: Array): Set { - val result = LinkedHashSet(mapCapacity(this.size + array.size)) - result.addAll(this) - result.addAll(array) - return result -} - -/** - * Returns a set containing all elements both of the original set and the given [collection]. - */ -public operator fun Set.plus(collection: Iterable): Set { - val result = LinkedHashSet(mapCapacity(collection.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2)) - result.addAll(this) - result.addAll(collection) + result.removeAll(elements) return result } @@ -84,12 +64,32 @@ public operator fun Set.plus(element: T): Set { } /** - * Returns a set containing all elements both of the original set and the given [sequence]. + * Returns a set containing all elements both of the original set and the given [elements] array. */ -public operator fun Set.plus(sequence: Sequence): Set { - val result = LinkedHashSet(mapCapacity(this.size * 2)) +public operator fun Set.plus(elements: Array): Set { + val result = LinkedHashSet(mapCapacity(this.size + elements.size)) result.addAll(this) - result.addAll(sequence) + result.addAll(elements) + return result +} + +/** + * Returns a set containing all elements both of the original set and the given [elements] collection. + */ +public operator fun Set.plus(elements: Iterable): Set { + val result = LinkedHashSet(mapCapacity(elements.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2)) + result.addAll(this) + result.addAll(elements) + return result +} + +/** + * Returns a set containing all elements both of the original set and the given [elements] sequence. + */ +public operator fun Set.plus(elements: Sequence): Set { + val result = LinkedHashSet(mapCapacity(this.size * 2)) + result.addAll(this) + result.addAll(elements) return result } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index 84d202c211a..9f1e3add9d3 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -50,51 +50,51 @@ fun generators(): List { } } - templates add f("plus(collection: Iterable)") { + templates add f("plus(elements: Iterable)") { operator(true) only(Iterables, Collections, Sets, Sequences) - doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." } + doc { f -> "Returns a list containing all elements of the original ${f.collection} and then all elements of the given [elements] collection." } returns("List") returns("SELF", Sets, Sequences) body { """ - if (this is Collection) return this.plus(collection) + if (this is Collection) return this.plus(elements) val result = ArrayList() result.addAll(this) - result.addAll(collection) + result.addAll(elements) return result """ } body(Collections) { """ - if (collection is Collection) { - val result = ArrayList(this.size + collection.size) + if (elements is Collection) { + val result = ArrayList(this.size + elements.size) result.addAll(this) - result.addAll(collection) + result.addAll(elements) return result } else { val result = ArrayList(this) - result.addAll(collection) + result.addAll(elements) return result } """ } // TODO: use immutable set builder when available - doc(Sets) { "Returns a set containing all elements both of the original set and the given [collection]." } + doc(Sets) { "Returns a set containing all elements both of the original set and the given [elements] collection." } body(Sets) { """ - val result = LinkedHashSet(mapCapacity(collection.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2)) + val result = LinkedHashSet(mapCapacity(elements.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2)) result.addAll(this) - result.addAll(collection) + result.addAll(elements) return result """ } doc(Sequences) { """ - Returns a sequence containing all elements of original sequence and then all elements of the given [collection]. + Returns a sequence containing all elements of original sequence and then all elements of the given [elements] collection. Note that the source sequence and the collection being added are iterated only when an `iterator` is requested from the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. @@ -102,47 +102,47 @@ fun generators(): List { } body(Sequences) { """ - return sequenceOf(this, collection.asSequence()).flatten() + return sequenceOf(this, elements.asSequence()).flatten() """ } } - templates add f("plus(array: Array)") { + templates add f("plus(elements: Array)") { operator(true) only(Iterables, Collections, Sets, Sequences) - doc { "Returns a list containing all elements of the original collection and then all elements of the given [array]." } + doc { "Returns a list containing all elements of the original collection and then all elements of the given [elements] array." } returns("List") returns("SELF", Sets, Sequences) body { """ - if (this is Collection) return this.plus(array) + if (this is Collection) return this.plus(elements) val result = ArrayList() result.addAll(this) - result.addAll(array) + result.addAll(elements) return result """ } body(Collections) { """ - val result = ArrayList(this.size + array.size) + val result = ArrayList(this.size + elements.size) result.addAll(this) - result.addAll(array) + result.addAll(elements) return result """ } - doc(Sets) { "Returns a set containing all elements both of the original set and the given [array]." } + doc(Sets) { "Returns a set containing all elements both of the original set and the given [elements] array." } body(Sets) { """ - val result = LinkedHashSet(mapCapacity(this.size + array.size)) + val result = LinkedHashSet(mapCapacity(this.size + elements.size)) result.addAll(this) - result.addAll(array) + result.addAll(elements) return result """ } doc(Sequences) { """ - Returns a sequence containing all elements of original sequence and then all elements of the given [array]. + Returns a sequence containing all elements of original sequence and then all elements of the given [elements] array. Note that the source sequence and the array being added are iterated only when an `iterator` is requested from the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. @@ -150,24 +150,24 @@ fun generators(): List { } body(Sequences) { """ - return this.plus(array.asList()) + return this.plus(elements.asList()) """ } } - templates add f("plus(sequence: Sequence)") { + templates add f("plus(elements: Sequence)") { operator(true) only(Iterables, Sets, Sequences) - doc { "Returns a list containing all elements of the original collection and then all elements of the given [sequence]." } + doc { "Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence." } returns("List") returns("SELF", Sets, Sequences) body { """ val result = ArrayList() result.addAll(this) - result.addAll(sequence) + result.addAll(elements) return result """ } @@ -175,25 +175,25 @@ fun generators(): List { """ val result = ArrayList(this.size + 10) result.addAll(this) - result.addAll(sequence) + result.addAll(elements) return result """ } // TODO: use immutable set builder when available - doc(Sets) { "Returns a set containing all elements both of the original set and the given [sequence]." } + doc(Sets) { "Returns a set containing all elements both of the original set and the given [elements] sequence." } body(Sets) { """ val result = LinkedHashSet(mapCapacity(this.size * 2)) result.addAll(this) - result.addAll(sequence) + result.addAll(elements) return result """ } doc(Sequences) { """ - Returns a sequence containing all elements of original sequence and then all elements of the given [sequence]. + Returns a sequence containing all elements of original sequence and then all elements of the given [elements] sequence. Note that the source sequence and the sequence being added are iterated only when an `iterator` is requested from the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. @@ -201,7 +201,7 @@ fun generators(): List { } body(Sequences) { """ - return sequenceOf(this, sequence).flatten() + return sequenceOf(this, elements).flatten() """ } } @@ -245,16 +245,16 @@ fun generators(): List { } - templates add f("minus(collection: Iterable)") { + templates add f("minus(elements: Iterable)") { operator(true) only(Iterables, Sets, Sequences) - doc { "Returns a list containing all elements of the original collection except the elements contained in the given [collection]." } + doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection." } returns("List") returns("SELF", Sets, Sequences) body { """ - val other = collection.convertToSetForSetOperationWith(this) + val other = elements.convertToSetForSetOperationWith(this) if (other.isEmpty()) return this.toList() @@ -262,10 +262,10 @@ fun generators(): List { """ } - doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [collection]." } + doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [elements] collection." } body(Sets) { """ - val other = collection.convertToSetForSetOperationWith(this) + val other = elements.convertToSetForSetOperationWith(this) if (other.isEmpty()) return this.toSet() if (other is Set) @@ -279,7 +279,7 @@ fun generators(): List { doc(Sequences) { """ - Returns a sequence containing all elements of original sequence except the elements contained in the given [collection]. + Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] collection. Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. @@ -289,7 +289,7 @@ fun generators(): List { """ return object: Sequence { override fun iterator(): Iterator { - val other = collection.convertToSetForSetOperation() + val other = elements.convertToSetForSetOperation() if (other.isEmpty()) return this@minus.iterator() else @@ -300,32 +300,32 @@ fun generators(): List { } } - templates add f("minus(array: Array)") { + templates add f("minus(elements: Array)") { operator(true) only(Iterables, Sets, Sequences) - doc { "Returns a list containing all elements of the original collection except the elements contained in the given [array]." } + doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] array." } returns("List") returns("SELF", Sets, Sequences) body { """ - if (array.isEmpty()) return this.toList() - val other = array.toHashSet() + if (elements.isEmpty()) return this.toList() + val other = elements.toHashSet() return this.filterNot { it in other } """ } - doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [array]." } + doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [elements] array." } body(Sets) { """ val result = LinkedHashSet(this) - result.removeAll(array) + result.removeAll(elements) return result """ } doc(Sequences) { """ - Returns a sequence containing all elements of original sequence except the elements contained in the given [array]. + Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] array. Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. @@ -333,10 +333,10 @@ fun generators(): List { } body(Sequences) { """ - if (array.isEmpty()) return this + if (elements.isEmpty()) return this return object: Sequence { override fun iterator(): Iterator { - val other = array.toHashSet() + val other = elements.toHashSet() return this@minus.filterNot { it in other }.iterator() } } @@ -344,34 +344,34 @@ fun generators(): List { } } - templates add f("minus(sequence: Sequence)") { + templates add f("minus(elements: Sequence)") { operator(true) only(Iterables, Sets) - doc { "Returns a list containing all elements of the original collection except the elements contained in the given [sequence]." } + doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence." } returns("List") returns("SELF", Sets, Sequences) body { """ - val other = sequence.toHashSet() + val other = elements.toHashSet() if (other.isEmpty()) return this.toList() return this.filterNot { it in other } """ } - doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [sequence]." } + doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [elements] sequence." } body(Sets) { """ val result = LinkedHashSet(this) - result.removeAll(sequence) + result.removeAll(elements) return result """ } doc(Sequences) { """ - Returns a sequence containing all elements of original sequence except the elements contained in the given [sequence]. + Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] sequence. Note that the source sequence and the sequence being subtracted are iterated only when an `iterator` is requested from the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. @@ -381,7 +381,7 @@ fun generators(): List { """ return object: Sequence { override fun iterator(): Iterator { - val other = sequence.toHashSet() + val other = elements.toHashSet() if (other.isEmpty()) return this@minus.iterator() else diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt index ebf06fe8349..dac76485751 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt @@ -104,29 +104,29 @@ fun specialJS(): List { } } - templates add f("plus(collection: Collection)") { + templates add f("plus(elements: Collection)") { only(ArraysOfObjects, ArraysOfPrimitives) returns("SELF") returns(ArraysOfObjects) { "Array" } - doc { "Returns an array containing all elements of the original array and then all elements of the given [collection]." } + doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] collection." } body { """ - return arrayPlusCollection(this, collection) + return arrayPlusCollection(this, elements) """ } } // This overload can cause nulls if array size is expanding, hence different return overload - templates add f("plus(array: SELF)") { + templates add f("plus(elements: SELF)") { only(ArraysOfObjects, ArraysOfPrimitives) - doc { "Returns an array containing all elements of the original array and then all elements of the given [array]." } + doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] array." } inline(true) annotations("""@Suppress("NOTHING_TO_INLINE")""") returns("SELF") returns(ArraysOfObjects) { "Array" } body { """ - return this.asDynamic().concat(array) + return this.asDynamic().concat(elements) """ } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt index 8f601ee90c3..a7f58a418ac 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt @@ -21,35 +21,35 @@ fun specialJVM(): List { } } - templates add f("plus(collection: Collection)") { + templates add f("plus(elements: Collection)") { operator(true) only(InvariantArraysOfObjects, ArraysOfPrimitives) returns("SELF") - doc { "Returns an array containing all elements of the original array and then all elements of the given [collection]." } + doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] collection." } body { """ var index = size - val result = Arrays.copyOf(this, index + collection.size) - for (element in collection) result[index++] = element + val result = Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element return result """ } } - templates add f("plus(array: SELF)") { + templates add f("plus(elements: SELF)") { operator(true) only(InvariantArraysOfObjects, ArraysOfPrimitives) - customSignature(InvariantArraysOfObjects) { "plus(array: Array)" } - doc { "Returns an array containing all elements of the original array and then all elements of the given [array]." } + customSignature(InvariantArraysOfObjects) { "plus(elements: Array)" } + doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] array." } returns("SELF") body { """ val thisSize = size - val arraySize = array.size + val arraySize = elements.size val result = Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(array, 0, result, thisSize, arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) return result """ }