3 ms·
Rough example below, partially taken from a book I have on Scala. //define it like this: def using[T <: {def close(): Unit }, S](obj: T) (operation: T => S) =
by grepgrep 15y ago
Rough example below, partially taken from a book I have on Scala.
//define it like this:
def using[T <: {def close(): Unit }, S](obj: T)
(operation: T => S) = {
val result = operation(obj)
obj.close()
result
}
//use it like this:
val writer = new FunkyWriter
using(writer) {
writer.write("outputting some data")
}
ARM was therefore possible in Scala before the Closable interface was even added to the Java libs.