The natural part is hard to satisfy. I would say that Kotlin property delegates were not natural to me when I first read about them, but now I use them like I never knew any better.
But I think the standard use
function satisfies efficiency and safety (otherwise it probably would not be part of the standard library). The only downside of use
is that it only works with Closeable
on the JVM target, but that is solvable: Generic use function
Assuming a generic version of use
, the remaining question is: Is it really that unnatural to nest a few use
s?
I am a method extraction fanatic, so when I am bothered by a deeply nested structure, I simply extract additional methods.