Elizeu Silva dos Santos
08/26/2022, 11:46 AMfun Route.customerRouting().
It means I am “injecting” customerRouting()
function into Route
class? Also, what is exactly the second parameter of this function: public fun Route.route(path: String, build: Route.() -> Unit)
. I am a java developer and some aspects of kotlin are a bit weird for meJoffrey
08/26/2022, 11:57 AMRoute
here is called the receiver of the extension function. It's really like other arguments. The only difference between a regular parameter and a receiver is how the argument is passed on the call site (it's just on the left instead of in the brackets, or it can be coming from an implicit this
) and how the parameter is used in the body of the function (it's an implicit this
)Elizeu Silva dos Santos
08/26/2022, 12:03 PMAugust Lilleaas
08/26/2022, 12:15 PMKlitos Kyriacou
08/26/2022, 1:25 PMbuild
is declared as Route.() -> Unit
means that if you pass a lambda expression to the function Route.route
, then inside the body of your lambda expression you can refer to this
(either explicitly or implicitly) as the object that is passed to your lambda function as the receiver argument.Johann Pardanaud
08/26/2022, 2:31 PMAugust Lilleaas
08/26/2022, 2:44 PM