Deprecate merge and introduce instead zip with transform.

Add zip with transform for Strings.
This commit is contained in:
Ilya Gorbunov
2015-10-07 04:42:59 +03:00
parent 12d9beb3a4
commit db93532e7c
8 changed files with 536 additions and 326 deletions
+408 -278
View File
@@ -8942,334 +8942,134 @@ public fun <T : Any> Array<out T?>.requireNoNulls(): Array<out T> {
return this as Array<out T>
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <T, R, V> Array<out T>.merge(array: Array<out R>, transform: (T, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> BooleanArray.merge(array: Array<out R>, transform: (Boolean, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> ByteArray.merge(array: Array<out R>, transform: (Byte, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> CharArray.merge(array: Array<out R>, transform: (Char, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> DoubleArray.merge(array: Array<out R>, transform: (Double, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> FloatArray.merge(array: Array<out R>, transform: (Float, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> IntArray.merge(array: Array<out R>, transform: (Int, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> LongArray.merge(array: Array<out R>, transform: (Long, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <R, V> ShortArray.merge(array: Array<out R>, transform: (Short, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> BooleanArray.merge(array: BooleanArray, transform: (Boolean, Boolean) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> ByteArray.merge(array: ByteArray, transform: (Byte, Byte) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> CharArray.merge(array: CharArray, transform: (Char, Char) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> DoubleArray.merge(array: DoubleArray, transform: (Double, Double) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> FloatArray.merge(array: FloatArray, transform: (Float, Float) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> IntArray.merge(array: IntArray, transform: (Int, Int) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> LongArray.merge(array: LongArray, transform: (Long, Long) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <V> ShortArray.merge(array: ShortArray, transform: (Short, Short) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <T, R, V> Array<out T>.merge(other: Iterable<R>, transform: (T, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> BooleanArray.merge(other: Iterable<R>, transform: (Boolean, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> ByteArray.merge(other: Iterable<R>, transform: (Byte, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> CharArray.merge(other: Iterable<R>, transform: (Char, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> DoubleArray.merge(other: Iterable<R>, transform: (Double, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> FloatArray.merge(other: Iterable<R>, transform: (Float, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> IntArray.merge(other: Iterable<R>, transform: (Int, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> LongArray.merge(other: Iterable<R>, transform: (Long, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <R, V> ShortArray.merge(other: Iterable<R>, transform: (Short, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
return zip(other, transform)
}
/**
@@ -9438,182 +9238,512 @@ public inline fun ShortArray.partition(predicate: (Short) -> Boolean): Pair<List
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Array<out T>.zip(array: Array<out R>): List<Pair<T, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> BooleanArray.zip(array: Array<out R>): List<Pair<Boolean, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> ByteArray.zip(array: Array<out R>): List<Pair<Byte, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> CharArray.zip(array: Array<out R>): List<Pair<Char, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> DoubleArray.zip(array: Array<out R>): List<Pair<Double, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> FloatArray.zip(array: Array<out R>): List<Pair<Float, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> IntArray.zip(array: Array<out R>): List<Pair<Int, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> LongArray.zip(array: Array<out R>): List<Pair<Long, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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 <R> ShortArray.zip(array: Array<out R>): List<Pair<Short, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(array) { t1, t2 -> t1 to t2 }
}
/**
* 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 <T, R, V> Array<out T>.zip(array: Array<out R>, transform: (T, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> BooleanArray.zip(array: Array<out R>, transform: (Boolean, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> ByteArray.zip(array: Array<out R>, transform: (Byte, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> CharArray.zip(array: Array<out R>, transform: (Char, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> DoubleArray.zip(array: Array<out R>, transform: (Double, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> FloatArray.zip(array: Array<out R>, transform: (Float, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> IntArray.zip(array: Array<out R>, transform: (Int, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> LongArray.zip(array: Array<out R>, transform: (Long, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <R, V> ShortArray.zip(array: Array<out R>, transform: (Short, R) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
}
/**
* 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<Pair<Boolean, Boolean>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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<Pair<Byte, Byte>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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<Pair<Char, Char>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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<Pair<Double, Double>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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<Pair<Float, Float>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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<Pair<Int, Int>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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<Pair<Long, Long>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(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<Pair<Short, Short>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(array) { t1, t2 -> t1 to t2 }
}
/**
* 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 <V> BooleanArray.zip(array: BooleanArray, transform: (Boolean, Boolean) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <V> ByteArray.zip(array: ByteArray, transform: (Byte, Byte) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <V> CharArray.zip(array: CharArray, transform: (Char, Char) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <V> DoubleArray.zip(array: DoubleArray, transform: (Double, Double) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <V> FloatArray.zip(array: FloatArray, transform: (Float, Float) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <V> IntArray.zip(array: IntArray, transform: (Int, Int) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <V> LongArray.zip(array: LongArray, transform: (Long, Long) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(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 <V> ShortArray.zip(array: ShortArray, transform: (Short, Short) -> V): List<V> {
val size = Math.min(size(), array.size())
val list = ArrayList<V>(size)
for (i in 0..size-1) {
list.add(transform(this[i], array[i]))
}
return list
}
/**
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Array<out T>.zip(other: Iterable<R>): List<Pair<T, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> BooleanArray.zip(other: Iterable<R>): List<Pair<Boolean, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> ByteArray.zip(other: Iterable<R>): List<Pair<Byte, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> CharArray.zip(other: Iterable<R>): List<Pair<Char, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> DoubleArray.zip(other: Iterable<R>): List<Pair<Double, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> FloatArray.zip(other: Iterable<R>): List<Pair<Float, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> IntArray.zip(other: Iterable<R>): List<Pair<Int, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> LongArray.zip(other: Iterable<R>): List<Pair<Long, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(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 <R> ShortArray.zip(other: Iterable<R>): List<Pair<Short, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(other) { t1, t2 -> t1 to t2 }
}
/**
* 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 <T, R, V> Array<out T>.zip(other: Iterable<R>, transform: (T, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> BooleanArray.zip(other: Iterable<R>, transform: (Boolean, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> ByteArray.zip(other: Iterable<R>, transform: (Byte, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> CharArray.zip(other: Iterable<R>, transform: (Char, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> DoubleArray.zip(other: Iterable<R>, transform: (Double, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> FloatArray.zip(other: Iterable<R>, transform: (Float, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> IntArray.zip(other: Iterable<R>, transform: (Int, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> LongArray.zip(other: Iterable<R>, transform: (Long, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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 <R, V> ShortArray.zip(other: Iterable<R>, transform: (Short, R) -> V): List<V> {
val arraySize = size()
val list = ArrayList<V>(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
}
/**
+33 -23
View File
@@ -1334,31 +1334,14 @@ public fun <T : Any> List<T?>.requireNoNulls(): List<T> {
return this as List<T>
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(array, transform)"))
public inline fun <T, R, V> Iterable<T>.merge(array: Array<out R>, transform: (T, R) -> V): List<V> {
val arraySize = array.size()
val list = ArrayList<V>(Math.min(collectionSizeOrDefault(10), arraySize))
var i = 0
for (element in this) {
if (i >= arraySize) break
list.add(transform(element, array[i++]))
}
return list
return zip(array, transform)
}
/**
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(other, transform)"))
public inline fun <T, R, V> Iterable<T>.merge(other: Iterable<R>, transform: (T, R) -> V): List<V> {
val first = iterator()
val second = other.iterator()
val list = ArrayList<V>(Math.min(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))
while (first.hasNext() && second.hasNext()) {
list.add(transform(first.next(), second.next()))
}
return list
return zip(other, transform)
}
/**
@@ -1510,14 +1493,41 @@ public operator fun <T> Iterable<T>.plus(sequence: Sequence<T>): List<T> {
* Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Iterable<T>.zip(array: Array<out R>): List<Pair<T, R>> {
return merge(array) { t1, t2 -> t1 to t2 }
return zip(array) { t1, t2 -> t1 to t2 }
}
/**
* 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 <T, R, V> Iterable<T>.zip(array: Array<out R>, transform: (T, R) -> V): List<V> {
val arraySize = array.size()
val list = ArrayList<V>(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 pairs built from elements of both collections with same indexes. List has length of shortest collection.
*/
public fun <T, R> Iterable<T>.zip(other: Iterable<R>): List<Pair<T, R>> {
return merge(other) { t1, t2 -> t1 to t2 }
return zip(other) { t1, t2 -> t1 to t2 }
}
/**
* 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 <T, R, V> Iterable<T>.zip(other: Iterable<R>, transform: (T, R) -> V): List<V> {
val first = iterator()
val second = other.iterator()
val list = ArrayList<V>(Math.min(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))
while (first.hasNext() && second.hasNext()) {
list.add(transform(first.next(), second.next()))
}
return list
}
/**
+9 -4
View File
@@ -795,11 +795,9 @@ public fun <T : Any> Sequence<T?>.requireNoNulls(): Sequence<T> {
return map { it ?: throw IllegalArgumentException("null element found in $this.") }
}
/**
* 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.
*/
@Deprecated("Use zip() with transform instead.", ReplaceWith("zip(sequence, transform)"))
public fun <T, R, V> Sequence<T>.merge(sequence: Sequence<R>, transform: (T, R) -> V): Sequence<V> {
return MergingSequence(this, sequence, transform)
return zip(sequence, transform)
}
/**
@@ -923,6 +921,13 @@ public fun <T, R> Sequence<T>.zip(sequence: Sequence<R>): Sequence<Pair<T, R>> {
return MergingSequence(this, sequence) { t1, t2 -> t1 to t2 }
}
/**
* 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 <T, R, V> Sequence<T>.zip(sequence: Sequence<R>, transform: (T, R) -> V): Sequence<V> {
return MergingSequence(this, sequence, transform)
}
/**
* Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied.
* If the collection could be huge, you can specify a non-negative value of [limit], in which case only the first [limit]
+11 -5
View File
@@ -733,11 +733,17 @@ public inline fun String.partition(predicate: (Char) -> Boolean): Pair<String, S
* 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<Pair<Char, Char>> {
val first = iterator()
val second = other.iterator()
val list = ArrayList<Pair<Char, Char>>(length())
while (first.hasNext() && second.hasNext()) {
list.add(first.next() to second.next())
return zip(other) { c1, c2 -> c1 to c2 }
}
/**
* Returns a list of values built from characters of both strings with same indexes using provided [transform]. List has length of shortest string.
*/
public inline fun <V> String.zip(other: String, transform: (Char, Char) -> V): List<V> {
val length = Math.min(this.length(), other.length())
val list = ArrayList<V>(length)
for (i in 0..length-1) {
list.add(transform(this[i], other[i]))
}
return list
}