All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generated._Generators.kt Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package kotlin

//
// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt
// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib
//

import kotlin.platform.*
import java.util.*

import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  Array.merge(array: Array, transform: (T, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  BooleanArray.merge(array: Array, transform: (Boolean, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  ByteArray.merge(array: Array, transform: (Byte, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  CharArray.merge(array: Array, transform: (Char, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  DoubleArray.merge(array: Array, transform: (Double, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  FloatArray.merge(array: Array, transform: (Float, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  IntArray.merge(array: Array, transform: (Int, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  LongArray.merge(array: Array, transform: (Long, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  ShortArray.merge(array: Array, transform: (Short, R) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  Iterable.merge(array: Array, transform: (T, R) -> V): List {
    val arraySize = array.size()
    val list = ArrayList(Math.min(collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in this) {
        if (i >= arraySize) break
        list.add(transform(element, array[i++]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  BooleanArray.merge(array: BooleanArray, transform: (Boolean, Boolean) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  ByteArray.merge(array: ByteArray, transform: (Byte, Byte) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  CharArray.merge(array: CharArray, transform: (Char, Char) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  DoubleArray.merge(array: DoubleArray, transform: (Double, Double) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  FloatArray.merge(array: FloatArray, transform: (Float, Float) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  IntArray.merge(array: IntArray, transform: (Int, Int) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  LongArray.merge(array: LongArray, transform: (Long, Long) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  ShortArray.merge(array: ShortArray, transform: (Short, Short) -> V): List {
    val size = Math.min(size(), array.size())
    val list = ArrayList(size)
    for (i in 0..size-1) {
        list.add(transform(this[i], array[i]))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  Array.merge(other: Iterable, transform: (T, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  BooleanArray.merge(other: Iterable, transform: (Boolean, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  ByteArray.merge(other: Iterable, transform: (Byte, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  CharArray.merge(other: Iterable, transform: (Char, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  DoubleArray.merge(other: Iterable, transform: (Double, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  FloatArray.merge(other: Iterable, transform: (Float, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  IntArray.merge(other: Iterable, transform: (Int, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  LongArray.merge(other: Iterable, transform: (Long, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  ShortArray.merge(other: Iterable, transform: (Short, R) -> V): List {
    val arraySize = size()
    val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize))
    var i = 0
    for (element in other) {
        if (i >= arraySize) break
        list.add(transform(this[i++], element))
    }
    return list
}

/**
 * Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
 */
public inline fun  Iterable.merge(other: Iterable, transform: (T, R) -> V): List {
    val first = iterator()
    val second = other.iterator()
    val list = ArrayList(Math.min(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))
    while (first.hasNext() && second.hasNext()) {
        list.add(transform(first.next(), second.next()))
    }
    return list
}

/**
 * Returns a sequence of values built from elements of both collections with same indexes using provided [transform]. Resulting sequence has length of shortest input sequences.
 */
public fun  Sequence.merge(sequence: Sequence, transform: (T, R) -> V): Sequence {
    return MergingSequence(this, sequence, transform)
}

/**
 * Returns a list containing all elements of the original collection except the elements contained in the given [array].
 */
public fun  Iterable.minus(array: Array): List {
    if (array.isEmpty()) return this.toList()
    val other = array.toHashSet()
    return this.filterNot { it in other }
}

/**
 * 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 fun  Sequence.minus(array: Array): Sequence {
    if (array.isEmpty()) return this
    return object: Sequence {
        override fun iterator(): Iterator {
            val other = array.toHashSet()
            return [email protected] { it in other }.iterator()
        }
    }
}

/**
 * Returns a set containing all elements of the original set except the elements contained in the given [array].
 */
public fun  Set.minus(array: Array): Set {
    val result = LinkedHashSet(this)
    result.removeAll(array)
    return result
}

/**
 * Returns a list containing all elements of the original collection except the elements contained in the given [collection].
 */
public 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 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 fun  Sequence.minus(collection: Iterable): Sequence {
    return object: Sequence {
        override fun iterator(): Iterator {
            val other = collection.convertToSetForSetOperation()
            if (other.isEmpty())
                return [email protected]()
            else
                return [email protected] { it in other }.iterator()
        }
    }
}

/**
 * Returns a set containing all elements of the original set except the elements contained in the given [collection].
 */
public fun  Set.minus(collection: Iterable): Set {
    val other = collection.convertToSetForSetOperationWith(this)
    if (other.isEmpty())
        return this.toSet()
    if (other is Set)
        return this.filterNotTo(LinkedHashSet()) { it in other }
    val result = LinkedHashSet(this)
    result.removeAll(other)
    return result
}

/**
 * Returns a list containing all elements of the original collection without the first occurrence of the given [element].
 */
public fun  Iterable.minus(element: T): List {
    val result = ArrayList(collectionSizeOrDefault(10))
    var removed = false
    return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true }
}

/**
 * Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element].
 */
public fun  Sequence.minus(element: T): Sequence {
    return object: Sequence {
        override fun iterator(): Iterator {
            var removed = false
            return [email protected] { if (!removed && it == element) { removed = true; false } else true }.iterator()
        }
    }
}

/**
 * Returns a set containing all elements of the original set except the given [element].
 */
public 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 list containing all elements of the original collection except the elements contained in the given [sequence].
 */
public fun  Iterable.minus(sequence: Sequence): List {
    val other = sequence.toHashSet()
    if (other.isEmpty())
        return this.toList()
    return this.filterNot { it in other }
}

/**
 * Returns a sequence containing all elements of original sequence except the elements contained in the given [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 fun  Sequence.minus(sequence: Sequence): Sequence {
    return object: Sequence {
        override fun iterator(): Iterator {
            val other = sequence.toHashSet()
            if (other.isEmpty())
                return [email protected]()
            else
                return [email protected] { it in other }.iterator()
        }
    }
}

/**
 * Returns a set containing all elements of the original set except the elements contained in the given [sequence].
 */
public fun  Set.minus(sequence: Sequence): Set {
    val result = LinkedHashSet(this)
    result.removeAll(sequence)
    return result
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun  Array.partition(predicate: (T) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun BooleanArray.partition(predicate: (Boolean) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun ByteArray.partition(predicate: (Byte) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun CharArray.partition(predicate: (Char) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun DoubleArray.partition(predicate: (Double) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun FloatArray.partition(predicate: (Float) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun IntArray.partition(predicate: (Int) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun LongArray.partition(predicate: (Long) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun ShortArray.partition(predicate: (Short) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun  Iterable.partition(predicate: (T) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original collection into pair of collections,
 * where *first* collection contains elements for which [predicate] yielded `true`,
 * while *second* collection contains elements for which [predicate] yielded `false`.
 */
public inline fun  Sequence.partition(predicate: (T) -> Boolean): Pair, List> {
    val first = ArrayList()
    val second = ArrayList()
    for (element in this) {
        if (predicate(element)) {
            first.add(element)
        } else {
            second.add(element)
        }
    }
    return Pair(first, second)
}

/**
 * Splits the original string into pair of strings,
 * where *first* string contains characters for which [predicate] yielded `true`,
 * while *second* string contains characters for which [predicate] yielded `false`.
 */
public inline fun String.partition(predicate: (Char) -> Boolean): Pair {
    val first = StringBuilder()
    val second = StringBuilder()
    for (element in this) {
        if (predicate(element)) {
            first.append(element)
        } else {
            second.append(element)
        }
    }
    return Pair(first.toString(), second.toString())
}

/**
 * Returns a list containing all elements of the original collection and then all elements of the given [array].
 */
public fun  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 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 sequence containing all elements of original sequence and then all elements of the given [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 fun  Sequence.plus(array: Array): Sequence {
    return this.plus(array.asList())
}

/**
 * Returns a set containing all elements both of the original set and the given [array].
 */
public fun  Set.plus(array: Array): Set {
    val result = LinkedHashSet(mapCapacity(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 [collection].
 */
public 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 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 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 fun  Sequence.plus(collection: Iterable): Sequence {
    return sequenceOf(this, collection.asSequence()).flatten()
}

/**
 * Returns a set containing all elements both of the original set and the given [collection].
 */
public 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)
    return result
}

/**
 * Returns a list containing all elements of the original collection and then the given [element].
 */
public fun  Collection.plus(element: T): List {
    val result = ArrayList(size() + 1)
    result.addAll(this)
    result.add(element)
    return result
}

/**
 * Returns a list containing all elements of the original collection and then the given [element].
 */
public fun  Iterable.plus(element: T): List {
    if (this is Collection) return this.plus(element)
    val result = ArrayList()
    result.addAll(this)
    result.add(element)
    return result
}

/**
 * Returns a sequence containing all elements of the original sequence and then the given [element].
 */
public fun  Sequence.plus(element: T): Sequence {
    return sequenceOf(this, sequenceOf(element)).flatten()
}

/**
 * Returns a set containing all elements of the original set and then the given [element].
 */
public fun  Set.plus(element: T): Set {
    val result = LinkedHashSet(mapCapacity(size() + 1))
    result.addAll(this)
    result.add(element)
    return result
}

/**
 * Returns a list containing all elements of the original collection and then all elements of the given [sequence].
 */
public fun  Collection.plus(sequence: Sequence): List {
    val result = ArrayList(this.size() + 10)
    result.addAll(this)
    result.addAll(sequence)
    return result
}

/**
 * Returns a list containing all elements of the original collection and then all elements of the given [sequence].
 */
public fun  Iterable.plus(sequence: Sequence): List {
    val result = ArrayList()
    result.addAll(this)
    result.addAll(sequence)
    return result
}

/**
 * Returns a sequence containing all elements of original sequence and then all elements of the given [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 fun  Sequence.plus(sequence: Sequence): Sequence {
    return sequenceOf(this, sequence).flatten()
}

/**
 * Returns a set containing all elements both of the original set and the given [sequence].
 */
public fun  Set.plus(sequence: Sequence): Set {
    val result = LinkedHashSet(mapCapacity(this.size() * 2))
    result.addAll(this)
    result.addAll(sequence)
    return result
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  Array.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  BooleanArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  ByteArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  CharArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  DoubleArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  FloatArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  IntArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  LongArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  ShortArray.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  Iterable.zip(array: Array): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun BooleanArray.zip(array: BooleanArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun ByteArray.zip(array: ByteArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun CharArray.zip(array: CharArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun DoubleArray.zip(array: DoubleArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun FloatArray.zip(array: FloatArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun IntArray.zip(array: IntArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun LongArray.zip(array: LongArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun ShortArray.zip(array: ShortArray): List> {
    return merge(array) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  Array.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  BooleanArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  ByteArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  CharArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  DoubleArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  FloatArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  IntArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  LongArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  ShortArray.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
 */
public fun  Iterable.zip(other: Iterable): List> {
    return merge(other) { t1, t2 -> t1 to t2 }
}

/**
 * Returns a list of pairs built from characters of both strings with same indexes. List has length of shortest collection.
 */
public fun String.zip(other: String): List> {
    val first = iterator()
    val second = other.iterator()
    val list = ArrayList>(length())
    while (first.hasNext() && second.hasNext()) {
        list.add(first.next() to second.next())
    }
    return list
}

/**
 * Returns a sequence of pairs built from elements of both collections with same indexes.
 * Resulting sequence has length of shortest input sequences.
 */
public fun  Sequence.zip(sequence: Sequence): Sequence> {
    return MergingSequence(this, sequence) { t1, t2 -> t1 to t2 }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy