Skip to content

Instantly share code, notes, and snippets.

@heath
Created January 17, 2020 20:55
Show Gist options
  • Save heath/510de0529593e56cb6b26699f83e14f6 to your computer and use it in GitHub Desktop.
Save heath/510de0529593e56cb6b26699f83e14f6 to your computer and use it in GitHub Desktop.
module Main where
-- | emulate a tennis game ignoring some of the details
import Lib
import Network.Wreq
import Data.Aeson (Value)
import Control.Lens
type Resp = Response [String]
type Score = (String, String)
changeWording :: Int -> String
changeWording score =
case score of
0 -> "love"
1 -> "15"
2 -> "30"
3 -> "40"
calculateScore :: [String] -> IO Score
calculateScore match = do
let aScore = foldr (\x acc -> if x == "A" then acc + 1 else acc) 0 match
let bScore = foldr (\x acc -> if x == "B" then acc + 1 else acc) 0 match
pure $ (changeWording aScore, changeWording bScore)
getMatch :: String -> IO [String]
getMatch url = do
r <- asJSON =<< get url :: IO Resp
pure $ r ^. responseBody
main :: IO ()
main = do
print =<< calculateScore =<< getMatch "https://c5-tennis.herokuapp.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment