-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
25 lines (20 loc) · 911 Bytes
/
Main.hs
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
module Main where
import qualified Data.ByteString.Lazy.Internal as C
import Data.Aeson
import Data.List
import Control.Arrow
import Lib
main :: IO ()
main = do activitiesEither <- eitherDecodeFileStrict "../input.json" :: IO (Either String [Activity])
let output = case activitiesEither of
-- It will not work properly for UTF-8 characters but for sake of a demonstration it's good enough
(Right activities) -> C.unpackChars $ process activities
(Left e) -> "Something went wrong: " ++ e
in (putStrLn output)
process :: [Activity] -> C.ByteString
process activities = encode $ onlyComments activities
onlyComments :: [Activity] -> [Activity]
onlyComments activites = filter isComment activites
isComment :: Activity -> Bool
isComment (Comment _ _) = True
isComment otherwise = False