Matt Robertson
01/27/2022, 10:11 PMUnit
to be a sort of anonymous extension function on a given class? I noticed it in the Compose code (I think) but I haven't been able to find it in the docs.
Example:
fun render(node: Node, action: Node.() -> Unit) {
node.action()
}
ephemient
01/27/2022, 10:28 PMrender
is a higher-order function taking a function type (or lambda) with receiver. https://kotlinlang.org/docs/lambdas.htmlMatt Robertson
01/27/2022, 10:33 PMephemient
01/27/2022, 10:34 PMfun
, which is not the only way to get a function type - a lambda expression { ... }
also doesephemient
01/27/2022, 10:34 PMephemient
01/27/2022, 10:35 PMMatt Robertson
01/27/2022, 10:36 PMLambda expressions can be used as function literals with receiver when the receiver type can be inferred from the context.
So if I'm understanding the terminology, in this case the lambda is not strictly speaking a "function literal" (since it is not defined as fun
) but is simply being used in the same way?ephemient
01/27/2022, 10:37 PMephemient
01/27/2022, 10:37 PMMatt Robertson
01/27/2022, 10:37 PM