12 Scope Functions
Scope functions are general utility functions in the Kotlin standard library that can help you write more expressive and concise code. In this chapter you will meet the six most commonly used scope functions – apply, let, run, with, also, and takeIf – and see examples of what they can do.
We will begin by introducing each of these extension functions, and then you will incorporate one of them into NyetHack.
Every scope function is called on a value, commonly known as the receiver, and takes in a lambda that defines the work you want to do with the value. The term receiver stems from the fact that Kotlin’s scope functions are extension functions under the hood, and receiver is the term for the subject of an ...
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