Scope Functions
let, run, apply, also and with run code on an object. apply returns the object and let returns the result.
Example
val p = StringBuilder().apply { append("a"); append("b") }
println(p)
val len = "hello".let { it.length }
println(len)
"x".also { println("got $it") }Exercise
Configure an object.
StringBuilder(). { append("x") }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.