also
-
[Kotlin] Scoping Functions apply vs. with, let, also, and runAndroid 2020. 11. 4. 15:06
Here is the definition of all 5 functions: inline fun with(receiver: T, block: T.() -> R): R { return receiver.block() } inline fun T.also(block: (T) -> Unit): T { block(this) return this } inline fun T.apply(block: T.() -> Unit): T { block() return this } inline fun T.let(block: (T) -> R): R { return block(this) } inline fun T.run(block: T.() -> R): R { return block() } using apply val peter = ..