-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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