I'm learning kotlin and has recently spotted an interesting way of writing kotlin but can't really understand it.
taken the code I'm learning from here
fun drawerImageLoader(actions: DrawerImageLoaderKt.() -> Unit): DrawerImageLoader.IDrawerImageLoader {
val loaderImpl = DrawerImageLoaderKt().apply(actions).build()
DrawerImageLoader.init(loaderImpl)
return loaderImpl
}
class DrawerImageLoaderKt {
...
}
why should drawerImageLoader
defined outside of class? why can't be in the class and within companion object
block?
Also, what does .()
mean in DrawerImageLoaderKt.()
?