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

kotlin.collections.Arrays.kt Maven / Gradle / Ivy

There is a newer version: 01.02.00-RPM
Show newest version
@file:kotlin.jvm.JvmMultifileClass
@file:kotlin.jvm.JvmName("ArraysKt")


package kotlin.collections

import java.util.*

/**
 * Returns a single list of all elements from all arrays in the given array.
 */
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.
 */
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 - 2024 Weber Informatics LLC | Privacy Policy