On the topic of inline functions which return func...
# language-proposals
d
On the topic of inline functions which return function types: Is it possible/realistic to have an optimization which inlines a return value if it is either: - A: invoked immediately, or - B: passed as an argument to another inline function ... but is not stored in a variable? E.g.
Copy code
inline val fooFunction: () -> Unit
  get() = { println("hello world") }

fun bar() {
  fooFunction() // immediate invocation results in complete inlining of "println" body
}
I think this is a pretty obscure use case, but could see it being beneficial for something like funKTionale (using partial application, etc)
🤔 1
d
There's at least one issue: currently, inliner works under assumption that there's a single lambda value passed as a given parameter. What to do with cases such as
Copy code
inline fun foo() = if (flag) { -> println("true") } else { println("false") }
In fact, I like the direction where it goes. We have some long-term plans for better compiler support of functional programming style. Most likely as a part of "JVM BE 2.0" that is currently in development.
👍 1