1{-# LANGUAGE FlexibleContexts #-}
3-- This example is adapted from Gabriel Gonzalez's pipes-concurrency package.
4-- https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html
7import Streamly.Prelude as S
8import Control.Monad (when)
9import Control.Monad.IO.Class (MonadIO(liftIO))
10import Control.Monad.State (MonadState, get, modify, runStateT, put)
12data Event = Harm Int | Heal Int deriving (Show)
14userAction :: MonadAsync m => SerialT m Event
15userAction = S.repeatM $ liftIO askUser
20 "potion" -> return (Heal 10)
22 _ -> putStrLn "What?" >> askUser
24acidRain :: MonadAsync m => SerialT m Event
25acidRain = asyncly $ constRate 1 $ S.repeatM $ liftIO $ return $ Harm 1
27game :: (MonadAsync m, MonadState Int m) => SerialT m ()
29 event <- userAction `parallel` acidRain
31 Harm n -> modify $ \h -> h - n
32 Heal n -> modify $ \h -> h + n
35 when (h <= 0) $ fail "You die!"
36 liftIO $ putStrLn $ "Health = " <> show h
40 putStrLn "Your health is deteriorating due to acid rain,\
41 \ type \"potion\" or \"quit\""
42 _ <- runStateT (runStream game) 60
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list