Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created January 17, 2012 14:55
Show Gist options
  • Save seanparsons/1626933 to your computer and use it in GitHub Desktop.
Save seanparsons/1626933 to your computer and use it in GitHub Desktop.
Useful code snippet to use when parsing large files in the Scala REPL
import scala.io.Source
def parseLines[T](file: String, transform: (Iterator[String]) => T): T = {
val log = Source.fromFile(file)
val logLines = log.getLines()
try { transform(logLines) } finally { log.close }
}
// Example usage.
// parseLines("verybigfile.txt", iterator.take(100).foreach(println))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment