Created
January 30, 2017 18:12
-
-
Save r-wheeler/2792ec789c73e3ec605d0261b26fec9e to your computer and use it in GitHub Desktop.
stateT
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
type Game[A] = StateT[IO,GameState, A] | |
val initState = GameState("apples","",10,3) | |
def liftIO[A](ioa: IO[A]) = StateT.lift[IO, GameState,A](ioa) | |
def runGame(): Game[Unit] = { | |
for { | |
in <- StateT.get[IO, GameState] | |
_ <- liftIO(putStrLn(in.show)) | |
//Show the initial State | |
guess <- StateT.lift[IO,GameState,String](getLine) | |
// prompts users | |
_ <- liftIO(putStrLn(guess)) | |
// prints user entered string | |
newState = GameState("pears","",5,5) | |
// testing to see if set works.. | |
_ = liftIO(putStrLn(newState.show)) | |
// prints what the state will be set to | |
_ = StateT.set[IO,GameState](newState) | |
// set the state | |
s <- StateT.get[IO,GameState] | |
// get the new state | |
_ <- liftIO(putStrLn(s.show)) | |
//Prints the original state | |
} yield () | |
} | |
//runGame.run(initState).run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment