runningFold
Returns a list containing successive accumulation values generated by applying operation from left to right to each character and current accumulator value that starts with initial value.
inline fun <R> CharSequence.runningFold(initial: R, operation: (acc: R, Char) -> R): List<R>(source)
val text = "abc"
val cumulativeCodes = text.runningFold(0) { acc, ch -> acc + ch.code }
println(cumulativeCodes) // prints [0, 97, 195, 300]
val prefixes = text.runningFold("") { acc, ch -> acc + ch }
println(prefixes) // prints [, a, ab, abc]