kotlin.collections.Arrays.kt Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("ArraysKt")
package kotlin.collections
/**
* Returns a single list of all elements from all arrays in the given array.
* @sample samples.collections.Arrays.Transformations.flattenArray
*/
public fun Array>.flatten(): List {
val result = ArrayList(sumBy { it.size })
for (element in this) {
result.addAll(element)
}
return result
}
/**
* Returns a pair of lists, where
* *first* list is built from the first values of each pair from this array,
* *second* list is built from the second values of each pair from this array.
* @sample samples.collections.Arrays.Transformations.unzipArray
*/
public fun Array>.unzip(): Pair, List> {
val listT = ArrayList(size)
val listR = ArrayList(size)
for (pair in this) {
listT.add(pair.first)
listR.add(pair.second)
}
return listT to listR
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy