mathew murphy
06/28/2019, 5:57 PMuse
and with
?Shawn
06/28/2019, 5:59 PMmathew murphy
06/28/2019, 6:00 PMdb.getConnection().useWith {
prepareStatement(...).useWith {
setString(1, "Hello sailor")
execute()
}
}
Shawn
06/28/2019, 6:00 PMT.run {}
has a signature of (T.() -> R) -> R
, maybe that’s what you want?prepareStatement
is a method on the connection from getConnection
?apply {}
if you’re just returning Unit
bezrukov
06/28/2019, 6:05 PMrun
or apply
Shawn
06/28/2019, 6:06 PMmathew murphy
06/28/2019, 6:12 PMMike
06/28/2019, 6:14 PMuse
and it
?
Or give the parameter a meaningful name to eliminate ambiguity in usage?
Sometimes less concision leads to higher readability.mathew murphy
06/28/2019, 6:14 PMuse
. I was just wondering if there was an even shorter way to do it.Mike
06/28/2019, 6:17 PMmathew murphy
06/28/2019, 6:20 PMgildor
06/29/2019, 6:42 AMdb.getConnection().use { connection ->
connection.prepareStatement(...).use { statement ->
statement.setString(1, "Hello sailor")
statement.execute()
}
}