on master help sign in
Fix nomenclature in examples
56cb8e6Harendra Kumar
examples/AcidRain.hs+3−3
@@ -12,7 +12,7 @@ import Data.Semigroup (cycle1)
12
12
13data Event = Harm Int | Heal Int | Quit deriving (Show)
13data Event = Harm Int | Heal Int | Quit deriving (Show)
14
14
15−userAction :: MonadIO m => StreamT m Event
15+userAction :: MonadIO m => SerialT m Event
16userAction = cycle1 $ liftIO askUser
16userAction = cycle1 $ liftIO askUser
17 where
17 where
18 askUser = do
18 askUser = do
@@ -22,10 +22,10 @@ userAction = cycle1 $ liftIO askUser
22 "quit" -> return Quit
22 "quit" -> return Quit
23 _ -> putStrLn "What?" >> askUser
23 _ -> putStrLn "What?" >> askUser
24
24
25−acidRain :: MonadIO m => StreamT m Event
25+acidRain :: MonadIO m => SerialT m Event
26acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
26acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
27
27
28−game :: (MonadParallel m, MonadState Int m) => StreamT m ()
28+game :: (MonadAsync m, MonadState Int m) => SerialT m ()
29game = do
29game = do
30 event <- userAction `parallel` acidRain
30 event <- userAction `parallel` acidRain
31 case event of
31 case event of
examples/ListDir.hs+3−3
@@ -1,17 +1,17 @@
1import Control.Monad.IO.Class (liftIO)
1import Control.Monad.IO.Class (liftIO)
2import Path.IO (listDir, getCurrentDir)
2import Path.IO (listDir, getCurrentDir)
3import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
3import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
4−import Streamly (runStream, asParAhead)
4+import Streamly (runStream, asyncly)
5
5
6-- | List the current directory recursively using concurrent processing
6-- | List the current directory recursively using concurrent processing
7--
7--
8-- This example demonstrates that there is little difference between regular
8-- This example demonstrates that there is little difference between regular
9-- IO code and concurrent streamly code. You can just remove
9-- IO code and concurrent streamly code. You can just remove
10−-- 'runStream . asParAhead' and this becomes your regular IO code.
10+-- 'runStream . asyncly' and this becomes your regular IO code.
11main :: IO ()
11main :: IO ()
12main = do
12main = do
13 hSetBuffering stdout LineBuffering
13 hSetBuffering stdout LineBuffering
14− runStream . asParAhead $ getCurrentDir >>= readdir
14+ runStream . asyncly $ getCurrentDir >>= readdir
15 where readdir d = do
15 where readdir d = do
16 (ds, fs) <- liftIO $ listDir d
16 (ds, fs) <- liftIO $ listDir d
17 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
17 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
examples/MergeSort.hs+5−5
@@ -7,20 +7,20 @@ import Streamly
7import Streamly.Prelude (once)
7import Streamly.Prelude (once)
8import qualified Streamly.Prelude as A
8import qualified Streamly.Prelude as A
9
9
10−getSorted :: Stream Word16
10+getSorted :: Serial Word16
11getSorted = do
11getSorted = do
12 g <- once getStdGen
12 g <- once getStdGen
13 let ls = take 100000 (randoms g) :: [Word16]
13 let ls = take 100000 (randoms g) :: [Word16]
14 foldMap return (sort ls)
14 foldMap return (sort ls)
15
15
16-- | merge two streams generating the elements from each in parallel
16-- | merge two streams generating the elements from each in parallel
17−mergeAsync :: Ord a => Stream a -> Stream a -> Stream a
17+mergeAsync :: Ord a => Serial a -> Serial a -> Serial a
18mergeAsync a b = do
18mergeAsync a b = do
19− x <- once $ async a
19+ x <- once $ mkAsync a
20− y <- once $ async b
20+ y <- once $ mkAsync b
21 merge x y
21 merge x y
22
22
23−merge :: Ord a => Stream a -> Stream a -> Stream a
23+merge :: Ord a => Serial a -> Serial a -> Serial a
24merge a b = do
24merge a b = do
25 a1 <- once $ A.uncons a
25 a1 <- once $ A.uncons a
26 case a1 of
26 case a1 of
examples/SearchQuery.hs+2−2
@@ -10,10 +10,10 @@ import Network.HTTP.Simple
10main :: IO ()
10main :: IO ()
11main = do
11main = do
12 putStrLn "Using parallel semigroup composition"
12 putStrLn "Using parallel semigroup composition"
13− runStream . asParallel $ google <> bing <> duckduckgo
13+ runStream . parallely $ google <> bing <> duckduckgo
14
14
15 putStrLn "\nUsing parallel applicative zip"
15 putStrLn "\nUsing parallel applicative zip"
16− runStream . asZipParallel $ (,,) <$> google <*> bing <*> duckduckgo
16+ runStream . zipAsyncly $ (,,) <$> google <*> bing <*> duckduckgo
17
17
18 where
18 where
19 get :: IsStream t => String -> t IO ()
19 get :: IsStream t => String -> t IO ()