Last active
January 20, 2018 00:47
-
-
Save yoshiyoshifujii/b29a5a891662bfa8429f3e4cc9d42144 to your computer and use it in GitHub Desktop.
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
import scala.collection.immutable.TreeMap | |
import scala.io.Source | |
object Main extends App { | |
val file = Source.fromFile("./hoge.txt", "utf-8") | |
val lines = file.getLines | |
val dateTimeSep = """- (\d\d\d\d)年(\d\d)月(\d\d)日 .曜日 (\d\d:\d\d)""".r | |
val articles = lines.foldLeft("" -> TreeMap.empty[String, String]) { (acc, line) => | |
val (marker, treeMap) = acc | |
line match { | |
case dateTimeSep(year, month, day, time) => | |
val nowDate = s"$year-$month-$day $time" | |
nowDate -> treeMap.+(nowDate -> "") | |
case _ => | |
val data = treeMap.getOrElse(marker, "") + line + "\n" | |
marker -> treeMap.+(marker -> data) | |
} | |
} | |
println(articles) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment