Implicit Receivers
Unlike the let() and also() methods, the run() and apply() methods executed their lambdas in the context of their own target. What’s cool about Kotlin is that the language and library implementors didn’t keep that as a privileged execution for themselves. Instead, they made it accessible very elegantly to every one using the language. If you’re eager to learn and execute such methods for your own code, the wait is over. And this technique is one of the most essential to create fluent syntax for DSLs, so it’s all the more exciting.
Passing a Receiver
In JavaScript, functions may take zero or more parameters, but you may also pass a context object—a receiver—using either the call() method or apply() function. Kotlin’s ability ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access