You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

23 lines
758 B

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Worldcup.EventsTeams (EventTeam(..), parseEventsTeams) where
import Data.Aeson
import Data.Aeson.Types
import Prelude as P
data EventTeam = EventTeam {
eventTeamId :: Int } deriving (Show)
instance FromJSON EventTeam where
parseJSON = withObject "team" $ \o -> do
eventTeamId <- o .: "team_id"
return EventTeam{..}
parseEventsTeams :: Either String [Value] -> [Int]
parseEventsTeams (Left x) = error x
parseEventsTeams (Right xs) = P.foldl reduce [] xs where
reduce acc x = case (parseEither parseJSON x :: Either String EventTeam) of
(Left s) -> error s
(Right v) -> eventTeamId v : acc