I boot into Kotlin and want to customize Arrayof Labelin the linker syntax template. I came up with the standard Kotlin ( apply) library function in combination with the helper function in collections ( forEach). Is it right to refer to the build template? For me, this means that the declaration, purpose, and configuration are done in one line / step. I appreciate any thoughts on how to write this in an even more compact and understandable "Kotlin-ish" form, or is this the preferred Kotlin syntax more or less. By the way, there are many ways to do this wrong (use letinstead applydoes not return the recipient).
val labels = arrayOf(Label("A"),Label("B"),Label("C"),Label("D")).apply {
this.forEach { it.prefWidth = 50.0 }
}
source
share