let and run: Transform and Scope
Apply let for null-safe transformations and run for local computations.
let and run
let uses it as the receiver; run uses this. Both return the lambda's last expression. Pick based on whether you prefer explicit references.
let Basics
let passes the receiver to the lambda as it. Useful for transforming a value or limiting a variable's scope.
fun main() {
val length = "Kotlin".let { it.length }
println(length) // 6
}