Kotlin 2 · Collections and lambdas
Use scope functions
let transforms an object, apply configures it, also adds a side effect, and run/with compute a result.
val result = name?.let { it.uppercase() }
val user = User(1, "Ada").also { println("created $it") }
Official Kotlin 2 documentation