Last active
April 14, 2020 18:54
-
-
Save stk132/7a30f0e06feb0fed161869652109e795 to your computer and use it in GitHub Desktop.
scala2.12で呼び出し元でstream closedになるケース
This file contains 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
def readGZIPFile[A](filePath: String, proc: String => Option[A]): Either[Throwable, Seq[A]] = { | |
val gs = new GZIPInputStream(new FileInputStream(filePath)) | |
val ss = Source.fromInputStream(gs, "UTF-8") | |
try { | |
val ret = ss.getLines().flatMap(line => proc(line)).toSeq | |
Right(ret) | |
} catch { | |
case NonFatal(t) => Left(t) | |
} finally { | |
ss.close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment