https://kotlinlang.org logo
#codereview
Title
# codereview
n

nikolaymetchev

06/01/2022, 10:32 AM
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

Klitos Kyriacou

06/01/2022, 2:07 PM
It could also be called
runClosing
since it does the same thing as the
run
function, and additionally it calls
close
.
n

nikolaymetchev

06/01/2022, 2:10 PM
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

Klitos Kyriacou

06/01/2022, 2:11 PM
run
does have a receiver (or, one of its two variants has) - https://kotlinlang.org/docs/scope-functions.html#function-selection
n

nikolaymetchev

06/01/2022, 2:14 PM
Ah, you are right. it could be called
runClosing
6 Views