with
Group operations.
The with Function
with is a scope function that takes an object as an argument (not as a receiver of a call) and runs a block with that object as this. It returns the lambda result.
Basic with Usage
You pass the object to with and access its members directly inside the block.
fun main() {
val name = "Kotlin"
val description = with(name) {
"$this has $length characters"
}
println(description)
}