scanIndexed

Returns a list containing successive accumulation values generated by applying operation from left to right to each character, its index in the original char sequence and current accumulator value that starts with initial value.

inline fun <R> CharSequence.scanIndexed(initial: R, operation: (index: Int, acc: R, Char) -> R): List<R>(source)
val text = "abcd"
val cumulative = text.scanIndexed(0) { index, acc, char ->
    acc + char.code + index   // add char code plus its index to the running total
}
println(cumulative)   // prints: [0, 98, 205, 314, 426]

Source