Instantly share code, notes, and snippets.

Embed
What would you like to do?
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