HN user

grepgrep

3 karma
Posts0
Comments3
View on HN
No posts found.

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.