The 'mapNotNull' function is a powerful tool in Kotlin that allows you to transform collections while simultaneously filtering out null values. This is particularly useful when you're working with collections that may contain nullable elements and you want to apply a transformation while ignoring any nulls in the process.
val numbers: List= listOf(1, 2, null, 4, null, 6) val doubledNonNullNumbers: List = numbers.mapNotNull { it?.let { it * 2 } } // Result: [2, 4, 8, 12]