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?Shawn
06/28/2019, 6:02 PMprepareStatement is a method on the connection from getConnection?Shawn
06/28/2019, 6:02 PMapply {} if you’re just returning Unitbezrukov
06/28/2019, 6:05 PMrun or applyShawn
06/28/2019, 6:06 PMmathew murphy
06/28/2019, 6:12 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.mathew murphy
06/28/2019, 6:15 PMMike
06/28/2019, 6:17 PMmathew murphy
06/28/2019, 6:20 PMmathew murphy
06/28/2019, 6:21 PMmathew murphy
06/28/2019, 6:21 PMgildor
06/29/2019, 6:42 AMdb.getConnection().use { connection ->
connection.prepareStatement(...).use { statement ->
statement.setString(1, "Hello sailor")
statement.execute()
}
}gildor
06/29/2019, 6:42 AMgildor
06/29/2019, 6:43 AM