In Scala, I can write something like this:
val something = { val temp1 = ... val temp2 = ... temp1 + temp2 }
As far as I know, the best way to do the same in Kotlin is:
val something = { val temp1 = ... val temp2 = ... temp1 + temp2 }()
This is actually a lambda with the type Unit → Int, which is called immediately. I wonder if this code can somehow improve? Maybe there is a built-in function that allows me to write val something = block {...} or something like this?
source share