Skip to content

Instantly share code, notes, and snippets.

@conikeec
Forked from seanparsons/ParseLines.scala
Created February 16, 2012 19:24
Show Gist options
  • Save conikeec/1847136 to your computer and use it in GitHub Desktop.
Save conikeec/1847136 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