Answers for "kotlin merge two lists with alternating values"

0

kotlin merge two lists with alternating values

fun <T> List<T>.mix(other: List<T>): List<T> {
    val first = iterator()
    val second = other.iterator()
    val list = ArrayList<T>(minOf(this.size, other.size))
    while (first.hasNext() && second.hasNext()) {
        list.add(first.next())
        list.add(second.next())
    }
    return list
}
Posted by: Guest on July-08-2021

Code answers related to "kotlin merge two lists with alternating values"

Browse Popular Code Answers by Language