August 2018
Beginner
178 pages
4h 56m
English
Kotlin has built-in language features for creating custom DSLs. Receiver functions and the Infix keyword (covered in the next section) are two of those features.
Although intended primarily for creating DSLs, receiver functions can be also useful in everyday programming and as we shall see later, the Kotlin standard library uses them in several utility functions.
We could say that receiver functions share some similarities with extension functions. They have the same syntax for marking the receiver and, inside the function, they can access members of the receiver instance. Here's how we'd define a receiver function type:
val hello: String.() -> Unit = { print("Hello $this") }
It's the same as a normal function type definition, ...
Read now
Unlock full access