mapIndexedNotNullTo
Applies the given transform function to each character and its index in the original char sequence and appends only the non-null results to the given destination.
@IgnorableReturnValueinline fun <R : Any, C : MutableCollection<in R>> CharSequence.mapIndexedNotNullTo(destination: C, transform: (index: Int, Char) -> R?): C(source)
val input = "a1b2c3"
val digitIndices = mutableListOf<Int>()
input.mapIndexedNotNullTo(digitIndices) { index, ch ->
if (ch.isDigit()) index else null
}
println(digitIndices) // prints: [1, 3, 5]