with

Calls the specified function block with the given receiver as its receiver and returns its result.

@IgnorableReturnValueinline fun <T, R> with(receiver: T, block: T.() -> R): R(source)
// Using `with` to build a string
val greeting = with(StringBuilder()) {
    append("Hello, ")
    append("world!")
    toString()
}
println(greeting)   // prints: Hello, world!

Source