Would anyone have an opinion if these 2 functions ...
# codereview
n
Would anyone have an opinion if these 2 functions combining
use
and
with
should be added to the standard library:
Copy code
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)
k
It could also be called
runClosing
since it does the same thing as the
run
function, and additionally it calls
close
.
n
The point of
use
and
with
is they have a receiver whereas
run
doesn’t, so it is unclear what you will be calling
close
on.
k
run
does have a receiver (or, one of its two variants has) - https://kotlinlang.org/docs/scope-functions.html#function-selection
n
Ah, you are right. it could be called
runClosing