https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
v

vbsteven

03/20/2023, 5:50 PM
I'm working with KotlinPoet and I'm wondering if a lambda with receiver was ever considered to make
beginControlFlow()
/
endControlFlow()
chains more readable?
Copy code
.controlFlow(".let") {
    add("%T.fromNativeValue(it)", returnTypeInfo.kotlinTypeName)
}
Although the trailing lambda will interfere with the varargs arguments and would need some additional wrapping in a function or
CodeBlock.Builder
z

Zac Sweers

03/20/2023, 5:51 PM
it's trivial to write your own extension
kotlinpoet focuses on making the building blocks good
v

vbsteven

03/20/2023, 5:52 PM
yes indeed, and that might be what we're doing. I was just wondering if that was considered, and if there are maybe reasons why I shouldn't.
e

ephemient

03/20/2023, 5:52 PM
Trailing lambdas can come after varargs, that's not necessarily an issue
17 Views