mapNotNullTo
Applies the given transform function to each character 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.mapNotNullTo(destination: C, transform: (Char) -> R?): C(source)
val text = "a1b2c3"
val digits = mutableListOf<Int>()
text.mapNotNullTo(digits) { ch ->
if (ch.isDigit()) ch.toString().toInt() else null
}
// digits now contains [1, 2, 3]