diff --git a/src/Session.hs b/src/Session.hs index 4f76cbf..683c98e 100644 --- a/src/Session.hs +++ b/src/Session.hs @@ -24,19 +24,15 @@ data State = stateFile :: FilePath stateFile = libDir "state" -ifM :: IO Bool -> IO a -> IO a -> IO a -ifM condition caseTrue caseFalse = - condition >>= (\b -> if b then caseTrue else caseFalse) - initial :: IO State initial = do createDirectoryIfMissing True libDir - ifM (doesFileExist stateFile) - (do - playerID <- read <$> readFile stateFile - return $ Connected {playerID, games = Map.empty} - ) - (return New) + fileExists <- doesFileExist stateFile + if fileExists + then do + playerID <- read <$> readFile stateFile + return $ Connected {playerID, games = Map.empty} + else return New store :: PlayerID -> IO () store = writeFile stateFile . show