Understanding let, apply, with, run in Kotlin
Issue #114
Picture worths thousand words. Code worths thousand pictures. I don’t understand much until I take a look at Standard.kt in Kotlin standard library.
1 | /** |
apply
returns T and accepts a block of typeT.() -> Unit
. This is called Function Literals with Receiver
Kotlin provides the ability to call a function literal with a specified receiver object. Inside the body of the function literal, you can call methods on that receiver object without any additional qualifiers. This is similar to extension functions, which allow you to access members of the receiver object inside the body of the function
let
returns R and accepts a block of typeT -> R
. Inside the block, you can accessit
which is it: implicit name of a single parameter