zip
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.
Since Kotlin
1.0Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//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.
Since Kotlin
1.0Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
val stringA = "abcd"
val stringB = "zyx"
val result = stringA.zip(stringB) { a, b -> "$a$b" }
println(result) // [az, by, cx]
//sampleEnd
}