on master help sign in
Use cycle1
0bde212Harendra Kumar
examples/game.hs+3−3
@@ -7,12 +7,12 @@ import Asyncly
7import Control.Concurrent (threadDelay)
7import Control.Concurrent (threadDelay)
8import Control.Monad (when)
8import Control.Monad (when)
9import Control.Monad.State
9import Control.Monad.State
10−import Data.Foldable (fold)
10+import Data.Semigroup (cycle1)
11
11
12data Event = Harm Int | Heal Int | Quit deriving (Show)
12data Event = Harm Int | Heal Int | Quit deriving (Show)
13
13
14userAction :: MonadIO m => AsyncT m Event
14userAction :: MonadIO m => AsyncT m Event
15−userAction = fold $ repeat $ liftIO $ askUser
15+userAction = cycle1 $ liftIO askUser
16 where
16 where
17 askUser = do
17 askUser = do
18 command <- getLine
18 command <- getLine
@@ -22,7 +22,7 @@ userAction = fold $ repeat $ liftIO $ askUser
22 _ -> putStrLn "What?" >> askUser
22 _ -> putStrLn "What?" >> askUser
23
23
24acidRain :: MonadIO m => AsyncT m Event
24acidRain :: MonadIO m => AsyncT m Event
25−acidRain = fold $ repeat $ liftIO (threadDelay 1000000) >> return (Harm 1)
25+acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
26
26
27game :: (MonadAsync m, MonadState Int m) => AsyncT m ()
27game :: (MonadAsync m, MonadState Int m) => AsyncT m ()
28game = do
28game = do