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.
 
 
 
 
 

25 lines
840 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 {
eventsTeamsEventId :: Int,
eventsTeamsTeamId :: Int } deriving (Show)
instance FromJSON EventTeam where
parseJSON = withObject "team" $ \o -> do
eventsTeamsEventId <- o .: "event_id"
eventsTeamsTeamId <- o .: "team_id"
return EventTeam{..}
parseEventsTeams :: Either String [Value] -> [EventTeam]
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) -> v : acc