zip

infix fun CharSequence.zip(
    other: CharSequence
): List<Pair<Char, Char>>
(source)

Returns a list of pairs built from the characters of this and the other char sequences with the same index The returned list has length of the shortest char sequence.



fun main(args: Array<String>) {
//sampleStart
val stringA = "abcd"
val stringB = "zyx"
println(stringA zip stringB) // [(a, z), (b, y), (c, x)]
//sampleEnd
}
inline fun <V> CharSequence.zip(
    other: CharSequence,
    transform: (a: Char, b: Char) -> V
): List<V>
(source)

Returns a list of values built from the characters of this and the other char sequences with the same index using the provided transform function applied to each pair of characters. The returned list has length of the shortest char sequence.



fun main(args: Array<String>) {
//sampleStart
val stringA = "abcd"
val stringB = "zyx"
val result = stringA.zip(stringB) { a, b -> "$a$b" }
println(result) // [az, by, cx]
//sampleEnd
}