mapIndexed
Returns a list containing the results of applying the given transform function to each character and its index in the original char sequence.
inline fun <R> CharSequence.mapIndexed(transform: (index: Int, Char) -> R): List<R>(source)
fun main() {
val text = "Kotlin"
val indexedChars: List<String> = text.mapIndexed { index, char ->
"$index -> $char"
}
println(indexedChars) // Output: [0 -> K, 1 -> o, 2 -> t, 3 -> l, 4 -> i, 5 -> n]
}