Created
January 18, 2018 15:16
-
-
Save fxfan/4b1905d181ae311a987d61f5fb9aab51 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
case class Diary(date: String, content: String) | |
object Diary { | |
def apply(s: String): Diary = { | |
val lines = s.lines.toSeq | |
Diary(lines.head, lines.tail.mkString("\n")) | |
} | |
} | |
val diary = """ | |
- 2018年01月19日 金曜日 22:00 | |
酒 | |
の | |
む。 | |
- 2018年01月18日 木曜日 22:00 | |
Scala | |
しま | |
した。 | |
- 2018年01月20日 土曜日 22:00 | |
ほ | |
げ | |
""" | |
val pattern = """- (\d\d\d\d)年(\d\d)月(\d\d)日 .曜日 (\d\d:\d\d)""".r | |
val diaries = diary.split(s"(?=${pattern})") | |
.map(_.trim) | |
.filter(!_.isEmpty) | |
.map(Diary(_)) | |
.sortBy(_.date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment