kool
kool copied to clipboard
Suggest KSL return make infix fun
https://github.com/fabmax/kool/blob/f7e6d2e9bc8f9b936a0f1f120d08af67c8b4ad43/kool-core/src/commonMain/kotlin/de/fabmax/kool/modules/ksl/lang/KslFunction.kt#L79
https://www.baeldung.com/kotlin/infix-functions
As far as I know infix functions only work between two arguments, so, witrh an infix return, you would need to write something before it to work:
kslFunctionBody.apply {
// this would not work because there is no argument left of return
`return` someValue
// this would work but is not better than the current non-infix variant
kslFunctionBody `return` someValue
}
Am I missing something?
According to https://kotlinlang.org/docs/functions.html#infix-notation
Infix functions must meet the following requirements:
- They must be member functions or extension functions.
- They must have a single parameter.
- The parameter must not accept variable number of arguments and must have no default value.
So, as we have KslScopeBuilder.return and one argument returnValue it should works
Yes you can declare it as an infix function, but it doesn't make a difference because you can't invoke it 'infix-style' as long as there is no argument left of it (like in my example above).
I mean I can make it infix, but it also won't make anything better (but it should not hurt either :smile:)