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

More collections and lambdas commands

All collections and lambdas commands · Kotlin 2 cheatsheet

Was this page helpful?