I guess I want to understand the magic of `init: B...
# getting-started
k
I guess I want to understand the magic of
init: BuildType.() -> Unit
🧵 6
j
This type is a function type. It defines
init
as a function which has a receiver of type
BuildType
, no parameters, and returns
Unit
(so no specific return value)
1
k
ty!
k
I see a slight inconsistency in the Kotlin syntax: for normal functions, if the last parameter is a lambda, you can omit the parentheses. But this is not the case for constructor parameters; hence we need the parentheses around the curly braces.
j
Yeah that's why I tend to avoid constructors with a single lambda. Usually a top-level function is fine
k
I tend to avoid constructors with a single lambda
Kotest is absolutely full of them!
j
Let me clarify: constructors of open classes (the ones that can potentially be used in a subclass declaration)