Function literals with a receiver
Just as functions have a function type, that allows them to be kept as an object, extension functions have a type that allows them to be kept this way. It is called function type with a receiver. It looks like a simple function type, but the receiver type is located before arguments (like in an extension definition):
var power: Int.(Int) -> Int
The introduction of a function type with receiver makes full cohesion between functions and types possible, because all functions can now be represented as objects. It can be defined using a lambda expression with a receiver or with an anonymous function with the receiver.
In a lambda expression with a receiver definition, the only difference is that we can refer to a receiver with this
, and we can explicitly use receiver elements. For lambda expressions, the type must be specified in a parameter, because there is no syntax to specify receiver type. Here is power
defined as a lambda expression with a receiver...