「using」関数を次のように定義しました。
def using[A, B <: {def close(): Unit}] (closeable: B) (f: B => A): A =
try { f(closeable) } finally { closeable.close() }
私はそれを次のように使用できます:
using(new PrintWriter("sample.txt")){ out =>
out.println("hellow world!")
}
今、「using」関数を定義して任意の数のパラメーターを取り、それらに個別にアクセスできるようにする方法に興味があります。
using(new BufferedReader(new FileReader("in.txt")), new PrintWriter("out.txt")){ (in, out) =>
out.println(in.readLIne)
}