@arocnies Thanks for the hint, I will use it as well. Yes, I know about working smart cast on local variables (unless they are captured in some non-inline closures!).
Of course you could still be stuck in a project where mutable state is prevalent and you aren’t in a position to fix it.
The point is that the Kotlin (especially JVM) is not designed as functional language/platform. Writing code in pure functional style may end up with tons of data being copied around. Truly functional languages, e.g. Haskell, have special implementation under the hood which prevents data copying wherever possible (among with other things which make its runtime different from imperative languages). So writing everything functional may not always be a good idea in an imperative language.
Anyway, thanks for the help! At least new idoms learned.