flatMapIndexed

Returns a single list of all elements yielded from results of transform function being invoked on each character and its index in the original char sequence.

@JvmName(name = "flatMapIndexedIterable")inline fun <R> CharSequence.flatMapIndexed(transform: (index: Int, Char) -> Iterable<R>): List<R>(source)
fun main() {
    val input = "abc"
    val result = input.flatMapIndexed { index, char ->
        listOf(char, index.toString())
    }
    println(result)  // [a, 0, b, 1, c, 2]
}

Source