Created
January 17, 2020 20:55
-
-
Save heath/510de0529593e56cb6b26699f83e14f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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