Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import java.io.PrintWriter
import scala.io.Source
implicit class Using[T <: AutoCloseable](resource: T) {
def foreach[R](op: T => R): R = {
try op(resource)
catch { case e: Exception => throw e }
finally resource.close()
}
}
for {
w1 <- new PrintWriter("col1.txt")
w2 <- new PrintWriter("col2.txt")
} {
Source.stdin.getLines().map(_.split("\t")).foreach {
case Array(col1, col2, _*) =>
w1.println(col1)
w2.println(col2)
case Array(col1) => w1.println(col1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.