-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.scala
30 lines (24 loc) · 839 Bytes
/
Main.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package example
import java.nio.file.Paths
import example.entities.{Activity, Comment}
import io.circe.syntax._
import io.circe.jawn.parseFile
import example.entities.Activity._
object Main {
def main(args: Array[String]): Unit = {
val activitiesEither = parseFile(Paths.get("../input.json").toFile).flatMap(_.as[List[Activity]])
val output = activitiesEither match {
case Right(activities) => process(activities)
case Left(e) => s"Something went wrong: $e"
}
println(output)
}
def process(activities: List[Activity]): String =
onlyComments(activities).asJson.spaces2
def onlyComments(activities: List[Activity]): List[Activity] =
activities.filter(isComment)
def isComment(a: Activity): Boolean = a match {
case Comment(_, _) => true
case _ => false
}
}