Skip to content

Instantly share code, notes, and snippets.

@Yuichiroh
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuichiroh/4ebe09d36a5c1a48d3fb to your computer and use it in GitHub Desktop.
Save Yuichiroh/4ebe09d36a5c1a48d3fb to your computer and use it in GitHub Desktop.
def withPrintWriter(files: String*)(op: Seq[PrintWriter] => Unit) {
val writers = files.map(f => new PrintWriter(f))
try op(writers)
finally writers.foreach(_.close)
}
withPrintWriter("/col1.txt",
"/col2.txt") { ws =>
Source.stdin.getLines().map(_.split("\t")).foreach {
case Array(col1, col2, _*) =>
ws(0).println(col1)
ws(1).println(col2)
case Array(col1) => ws(0).println(col1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment