Skip to content

Instantly share code, notes, and snippets.

@r-wheeler
Created January 30, 2017 18:12
Show Gist options
  • Save r-wheeler/2792ec789c73e3ec605d0261b26fec9e to your computer and use it in GitHub Desktop.
Save r-wheeler/2792ec789c73e3ec605d0261b26fec9e to your computer and use it in GitHub Desktop.
stateT
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