nikolaymetchev
06/01/2022, 10:32 AMuse
and with
should be added to the standard library:
inline fun <T : AutoCloseable?, R> T.useWith(block: T.() -> R): R = use(block)
inline fun <T : Closeable?, R> T.useWith(block: T.() -> R): R = use(block)
Klitos Kyriacou
06/01/2022, 2:07 PMrunClosing
since it does the same thing as the run
function, and additionally it calls close
.nikolaymetchev
06/01/2022, 2:10 PMuse
and with
is they have a receiver whereas run
doesn’t, so it is unclear what you will be calling close
on.Klitos Kyriacou
06/01/2022, 2:11 PMrun
does have a receiver (or, one of its two variants has) - https://kotlinlang.org/docs/scope-functions.html#function-selectionKlitos Kyriacou
06/01/2022, 2:13 PMnikolaymetchev
06/01/2022, 2:14 PMrunClosing