@@ -170,7 +170,6 @@ module Streamly.Tutorial
173−import Streamly hiding (foldWith, foldMapWith, forEachWith)
174import Streamly.Prelude
173import Streamly.Prelude
175import Data.Semigroup
174import Data.Semigroup
176import Control.Applicative
175import Control.Applicative
@@ -345,8 +344,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
345-- GHCi session and import these lines to start playing.
344-- GHCi session and import these lines to start playing.
348−-- > import "Streamly"
347+-- > import "Streamly.Prelude" ((|:), (|&))
349−-- > import "Streamly.Prelude" ((|:))
350-- > import qualified "Streamly.Prelude" as S
348-- > import qualified "Streamly.Prelude" as S
352-- > import Control.Concurrent
350-- > import Control.Concurrent
@@ -412,15 +410,19 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
414-- > let p n = threadDelay (n * 1000000) >> return n
412-- > let p n = threadDelay (n * 1000000) >> return n
415−-- > S.'toList' $ 'parallely' $ p 3 |: p 2 |: p 1 |: S.'nil'
414+-- > S.'toList' $ S.'parallely' $ p 3 |: p 2 |: p 1 |: S.'nil'
416-- [1,2,3]
415-- [1,2,3]
416+-- (3.01 secs, 2,018,432 bytes)
417−-- > S.'toList' $ 'aheadly' $ p 3 |: p 2 |: p 1 |: S.'nil'
417+-- > S.'toList' $ S.'aheadly' $ p 3 |: p 2 |: p 1 |: S.'nil'
418-- [3,2,1]
418-- [3,2,1]
419+-- (3.01 secs, 2,055,880 bytes)
420-- The following finishes in 10 seconds (100 seconds when serial):
421-- The following finishes in 10 seconds (100 seconds when serial):
423−-- > S.drain $ 'asyncly' $ S.'replicateM' 10 $ p 10
424+-- > S.'drain' $ S.'asyncly' $ S.'replicateM' 10 $ p 10
425+-- (10.01 secs, 2,080,320 bytes)
@@ -456,7 +458,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
456-- numbers them and prints them:
458-- numbers them and prints them:
460-- import qualified "Streamly.Prelude" as S
461-- import qualified "Streamly.Prelude" as S
461-- import Data.Char (toUpper)
462-- import Data.Char (toUpper)
462-- import Data.Function ((&))
463-- import Data.Function ((&))
@@ -482,7 +483,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
484-- > let p n = threadDelay (n * 1000000) >> return n
485-- > let p n = threadDelay (n * 1000000) >> return n
485−-- > S.'drain' $ S.aheadly $ S.'mapM' (\\x -> p 1 >> print x) (serially $ S.repeatM (p 1))
486+-- > S.'drain' $ S.'aheadly' $ S.'mapM' (\\x -> p 1 >> print x) (S.'serially' $ S.'repeatM' (p 1))
@@ -515,7 +516,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
515-- not explicitly specified use the imports shown below.
516-- not explicitly specified use the imports shown below.
519-- import "Streamly.Prelude" ((|:), nil)
519-- import "Streamly.Prelude" ((|:), nil)
520-- import qualified "Streamly.Prelude" as S
520-- import qualified "Streamly.Prelude" as S
@@ -553,7 +553,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
556−-- main = S.'drain' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
556+-- main = S.'drain' $ (print 1 |: print 2 |: S.nil) <> (print 3 |: print 4 |: S.nil)
@@ -580,7 +580,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
580-- irrespective of the type of stream:
580-- irrespective of the type of stream:
583−-- main = S.'drain' $ (print 1 |: print 2 |: nil) \`serial` (print 3 |: print 4 |: nil)
583+-- main = S.'drain' $ (print 1 |: print 2 |: S.nil) \`S.serial` (print 3 |: print 4 |: S.nil)
586-- $interleaved
586-- $interleaved
@@ -597,7 +597,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
597-- The following example prints the sequence 1, 3, 2, 4
597-- The following example prints the sequence 1, 3, 2, 4
600−-- main = S.'drain' . 'wSerially' $ (print 1 |: print 2 |: nil) <> (print 3 |: print 4 |: nil)
600+-- main = S.'drain' . S.'wSerially' $ (print 1 |: print 2 |: S.'nil') <> (print 3 |: print 4 |: S.'nil')
@@ -612,7 +612,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
612-- thread and take a combined total of @3 + 2 + 1 = 6@ seconds:
612-- thread and take a combined total of @3 + 2 + 1 = 6@ seconds:
615−-- main = S.'drain' . 'wSerially' $ delay 3 <> delay 2 <> delay 1
615+-- main = S.'drain' . S.'wSerially' $ delay 3 <> delay 2 <> delay 1
618-- ThreadId 36: Delay 3
618-- ThreadId 36: Delay 3
@@ -626,7 +626,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
626-- combinator in the following example:
626-- combinator in the following example:
629−-- main = S.'drain' $ (print 1 |: print 2 |: nil) \`wSerial` (print 3 |: print 4 |: nil)
629+-- main = S.'drain' $ (print 1 |: print 2 |: S.'nil') \`S.wSerial` (print 3 |: print 4 |: S.'nil')
@@ -656,7 +656,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
658-- main = do
658-- main = do
659−-- xs \<- S.'toList' . 'aheadly' $ (p 1 |: p 2 |: nil) <> (p 3 |: p 4 |: nil)
659+-- xs \<- S.'toList' . S.'aheadly' $ (p 1 |: p 2 |: S.nil) <> (p 3 |: p 4 |: S.nil)
660-- print xs
660-- print xs
661-- where p n = threadDelay 1000000 >> return n
661-- where p n = threadDelay 1000000 >> return n
@@ -693,7 +693,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
695-- main = do
695-- main = do
696−-- xs \<- S.'toList' . 'asyncly' $ (p 1 |: p 2 |: nil) <> (p 3 |: p 4 |: nil)
696+-- xs \<- S.'toList' . S.'asyncly' $ (p 1 |: p 2 |: S.'nil') <> (p 3 |: p 4 |: S.'nil')
697-- print xs
697-- print xs
698-- where p n = threadDelay 1000000 >> return n
698-- where p n = threadDelay 1000000 >> return n
@@ -708,7 +708,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
710-- main = do
710-- main = do
711−-- xs \<- S.'toList' . 'asyncly' $ (serially $ p 1 |: p 2 |: nil) <> (serially $ p 3 |: p 4 |: nil)
711+-- xs \<- S.'toList' . S.'asyncly' $ (S.'serially' $ p 1 |: p 2 |: S.'nil') <> (serially $ p 3 |: p 4 |: S.'nil')
712-- print xs
712-- print xs
713-- where p n = threadDelay 1000000 >> return n
713-- where p n = threadDelay 1000000 >> return n
@@ -722,7 +722,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
722-- (3, 2, 1) = 3@ seconds:
722-- (3, 2, 1) = 3@ seconds:
725−-- main = S.'drain' . 'asyncly' $ delay 3 '<>' delay 2 '<>' delay 1
725+-- main = S.'drain' . S.'asyncly' $ delay 3 '<>' delay 2 '<>' delay 1
728-- ThreadId 42: Delay 1
728-- ThreadId 42: Delay 1
@@ -741,7 +741,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
741-- second as all of the actions are concurrent.
741-- second as all of the actions are concurrent.
744−-- main = S.'drain' . 'asyncly' $ (delay 1 <> delay 2) <> (delay 3 <> delay 4)
744+-- main = S.'drain' . S.'asyncly' $ (delay 1 <> delay 2) <> (delay 3 <> delay 4)
@@ -758,7 +758,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
758-- even if none of them blocks:
758-- even if none of them blocks:
761−-- main = S.'drain' . 'asyncly' $ traced (sqrt 9) '<>' traced (sqrt 16) '<>' traced (sqrt 25)
761+-- main = S.'drain' . S.'asyncly' $ traced (sqrt 9) '<>' traced (sqrt 16) '<>' traced (sqrt 25)
762-- where traced m = S.'yieldM' (myThreadId >>= print) >> return m
762-- where traced m = S.'yieldM' (myThreadId >>= print) >> return m
@@ -776,7 +776,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
776-- not used the 'asyncly' combinator in the following example:
776-- not used the 'asyncly' combinator in the following example:
779−-- main = S.'drain' $ delay 3 \`async` delay 2 \`async` delay 1
779+-- main = S.'drain' $ delay 3 \`S.'async'` delay 2 \`S.'async'` delay 1
782-- ThreadId 42: Delay 1
782-- ThreadId 42: Delay 1
@@ -819,7 +819,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
819-- first traversal order but this is not guaranteed.
819-- first traversal order but this is not guaranteed.
822−-- main = S.'drain' . 'wAsyncly' $ (serially $ print 1 |: print 2 |: nil) <> (serially $ print 3 |: print 4 |: nil)
822+-- main = S.'drain' . S.'wAsyncly' $ (S.'serially' $ print 1 |: print 2 |: S.'nil') <> (S.'serially' $ print 3 |: print 4 |: S.'nil')
@@ -834,7 +834,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
834-- the 'wAsyncly' combinator in the following example:
834-- the 'wAsyncly' combinator in the following example:
837−-- main = S.'drain' $ delay 3 \`wAsync` delay 2 \`wAsync` delay 1
837+-- main = S.'drain' $ delay 3 \S.`wAsync` delay 2 \S.`wAsync` delay 1
840-- ThreadId 42: Delay 1
840-- ThreadId 42: Delay 1
@@ -873,11 +873,10 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
873-- package to run this example:
873-- package to run this example:
877-- import qualified Streamly.Prelude as S
876-- import qualified Streamly.Prelude as S
878-- import Network.HTTP.Simple
877-- import Network.HTTP.Simple
880−-- main = S.'drain' . 'parallely' $ google \<> bing \<> duckduckgo
879+-- main = S.'drain' . S.'parallely' $ google \<> bing \<> duckduckgo
882-- google = get "https://www.google.com/search?q=haskell"
881-- google = get "https://www.google.com/search?q=haskell"
883-- bing = get "https://www.bing.com/search?q=haskell"
882-- bing = get "https://www.bing.com/search?q=haskell"
@@ -891,7 +890,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
891-- 'parallely' combinator in the following example:
890-- 'parallely' combinator in the following example:
894−-- main = S.'drain' $ delay 3 \`parallel` delay 2 \`wAsync` delay 1
893+-- main = S.'drain' $ delay 3 \`S.'parallel'` delay 2 \`S.'wAsync'` delay 1
897-- ThreadId 42: Delay 1
896-- ThreadId 42: Delay 1
@@ -921,27 +920,26 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
921-- style using 'fold' or 'foldMap'. We have also provided some fold utilities
920-- style using 'fold' or 'foldMap'. We have also provided some fold utilities
922-- to fold streams using the polymorphic combine operations:
921-- to fold streams using the polymorphic combine operations:
924−-- * 'foldWith' is like 'fold', it folds a 'Foldable' container of streams
923+-- * 'concatFoldableWith' is like 'fold', it folds a 'Foldable' container of
925−-- using the given composition operator.
924+-- streams using the given composition operator.
926−-- * 'foldMapWith' is like 'foldMap', it folds like @foldWith@ but also maps a
925+-- * 'concatMapFoldableWith' is like 'foldMap', it folds like
927−-- function before folding.
926+-- @concatFoldableWith@ but also maps a function before folding.
928−-- * 'forEachWith' is like @foldMapwith@ but the container argument comes before
927+-- * 'concatForFoldableWith' is like @concatMapFoldableWith@ but the container
929−-- the function argument.
928+-- argument comes before the function argument.
931-- All of the following are equivalent and start ten concurrent tasks each with
930-- All of the following are equivalent and start ten concurrent tasks each with
932-- a delay from 1 to 10 seconds, resulting in the printing of each number every
931-- a delay from 1 to 10 seconds, resulting in the printing of each number every
933-- second:
932-- second:
937-- import qualified "Streamly.Prelude" as S
935-- import qualified "Streamly.Prelude" as S
938-- import Control.Concurrent
936-- import Control.Concurrent
940-- main = do
938-- main = do
941−-- S.'drain' $ 'asyncly' $ foldMap delay [1..10]
939+-- S.'drain' $ S.'asyncly' $ foldMap delay [1..10]
942−-- S.'drain' $ S.'foldWith' 'async' (map delay [1..10])
940+-- S.'drain' $ S.'concatFoldableWith' S.'async' (map delay [1..10])
943−-- S.'drain' $ S.'foldMapWith' 'async' delay [1..10]
941+-- S.'drain' $ S.'concatMapFoldableWith' S.'async' delay [1..10]
944−-- S.'drain' $ S.'forEachWith' 'async' [1..10] delay
942+-- S.'drain' $ S.'concatForFoldableWith' S.'async' [1..10] delay
945-- where delay n = S.'yieldM' $ threadDelay (n * 1000000) >> print n
943-- where delay n = S.'yieldM' $ threadDelay (n * 1000000) >> print n
@@ -987,7 +985,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
987-- instead.
985-- instead.
991-- import qualified "Streamly.Prelude" as S
988-- import qualified "Streamly.Prelude" as S
993-- main = S.'drain' $ do
990-- main = S.'drain' $ do
@@ -1009,12 +1006,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1009-- written like this:
1006-- written like this:
1012−-- import "Streamly"
1013-- import qualified "Streamly.Prelude" as S
1009-- import qualified "Streamly.Prelude" as S
1015-- import Control.Monad (forever)
1011-- import Control.Monad (forever)
1017−-- main = S.'drain' $ forever $ S.yieldM getLine >>= S.yieldM . putStrLn
1013+-- main = S.'drain' $ forever $ S.'yieldM' getLine >>= S.'yieldM' . putStrLn
1020-- When multiple streams are composed using this style they nest in a DFS
1016-- When multiple streams are composed using this style they nest in a DFS
@@ -1023,7 +1019,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1023-- loops in imperative programming.
1019-- loops in imperative programming.
1026−-- import "Streamly"
1027-- import qualified "Streamly.Prelude" as S
1022-- import qualified "Streamly.Prelude" as S
1029-- main = S.'drain' $ do
1024-- main = S.'drain' $ do
@@ -1052,10 +1047,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1052-- type of the stream as 'Ahead'.
1047-- type of the stream as 'Ahead'.
1055−-- import "Streamly"
1056-- import qualified "Streamly.Prelude" as S
1050-- import qualified "Streamly.Prelude" as S
1058−-- comp = S.'toList' . 'aheadly' $ do
1052+-- comp = S.'toList' . S.'aheadly' $ do
1059-- x <- S.'fromFoldable' [3,2,1]
1053-- x <- S.'fromFoldable' [3,2,1]
1060-- delay x >> return x
1054-- delay x >> return x
@@ -1093,10 +1087,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1093-- type of the stream as 'Async'.
1087-- type of the stream as 'Async'.
1096−-- import "Streamly"
1097-- import qualified "Streamly.Prelude" as S
1090-- import qualified "Streamly.Prelude" as S
1099−-- main = S.'drain' . 'asyncly' $ do
1092+-- main = S.'drain' . S.'asyncly' $ do
1100-- x <- S.'fromFoldable' [3,2,1]
1093-- x <- S.'fromFoldable' [3,2,1]
1101-- delay x
1094-- delay x
@@ -1120,10 +1113,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1120-- on the demand from the consumer of the stream.
1113-- on the demand from the consumer of the stream.
1123−-- import "Streamly"
1124-- import qualified "Streamly.Prelude" as S
1116-- import qualified "Streamly.Prelude" as S
1126−-- main = S.'drain' . 'asyncly' $ do
1118+-- main = S.'drain' . S.'asyncly' $ do
1127-- x <- S.'fromFoldable' [1,2]
1119-- x <- S.'fromFoldable' [1,2]
1128-- y <- S.'fromFoldable' [3,4]
1120-- y <- S.'fromFoldable' [3,4]
1129-- S.'yieldM' $ putStrLn $ show (x, y)
1121-- S.'yieldM' $ putStrLn $ show (x, y)
@@ -1145,10 +1137,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1145-- type of the stream as 'WSerial'.
1137-- type of the stream as 'WSerial'.
1148−-- import "Streamly"
1149-- import qualified "Streamly.Prelude" as S
1140-- import qualified "Streamly.Prelude" as S
1151−-- main = S.'drain' . 'wSerially' $ do
1142+-- main = S.'drain' . S.'wSerially' $ do
1152-- x <- S.'fromFoldable' [1,2]
1143-- x <- S.'fromFoldable' [1,2]
1153-- y <- S.'fromFoldable' [3,4]
1144-- y <- S.'fromFoldable' [3,4]
1154-- S.yieldM $ putStrLn $ show (x, y)
1145-- S.yieldM $ putStrLn $ show (x, y)
@@ -1173,10 +1164,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1173-- specify the type of the stream as 'WAsync'.
1164-- specify the type of the stream as 'WAsync'.
1176−-- import "Streamly"
1177-- import qualified "Streamly.Prelude" as S
1167-- import qualified "Streamly.Prelude" as S
1179−-- main = S.'drain' . 'wAsyncly' $ do
1169+-- main = S.'drain' . S.'wAsyncly' $ do
1180-- x <- S.'fromFoldable' [1,2]
1170-- x <- S.'fromFoldable' [1,2]
1181-- y <- S.'fromFoldable' [3,4]
1171-- y <- S.'fromFoldable' [3,4]
1182-- S.'yieldM' $ putStrLn $ show (x, y)
1172-- S.'yieldM' $ putStrLn $ show (x, y)
@@ -1199,10 +1189,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1199-- annotation can be used to specify the type of the stream as 'Parallel'.
1189-- annotation can be used to specify the type of the stream as 'Parallel'.
1202−-- import "Streamly"
1203-- import qualified "Streamly.Prelude" as S
1192-- import qualified "Streamly.Prelude" as S
1205−-- main = S.'drain' . 'parallely' $ do
1194+-- main = S.'drain' . S.'parallely' $ do
1206-- x <- S.'fromFoldable' [3,2,1]
1195-- x <- S.'fromFoldable' [3,2,1]
1207-- delay x
1196-- delay x
@@ -1220,10 +1209,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1220-- specific mode of composition. For example take a look at the following code.
1209-- specific mode of composition. For example take a look at the following code.
1223−-- import "Streamly"
1224-- import qualified "Streamly.Prelude" as S
1212-- import qualified "Streamly.Prelude" as S
1226−-- composed :: (IsStream t, Monad (t IO)) => t IO ()
1214+-- composed :: (S.IsStream t, Monad (t IO)) => t IO ()
1227-- composed = do
1215-- composed = do
1228-- sz <- sizes
1216-- sz <- sizes
1229-- cl <- colors
1217-- cl <- colors
@@ -1240,11 +1228,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1240-- Now we can interpret this in whatever way we want:
1228-- Now we can interpret this in whatever way we want:
1243−-- main = S.'drain' . 'serially' $ composed
1231+-- main = S.'drain' . S.'serially' $ composed
1244−-- main = S.'drain' . 'wSerially' $ composed
1232+-- main = S.'drain' . S.'wSerially' $ composed
1245−-- main = S.'drain' . 'asyncly' $ composed
1233+-- main = S.'drain' . S.'asyncly' $ composed
1246−-- main = S.'drain' . 'wAsyncly' $ composed
1234+-- main = S.'drain' . S.'wAsyncly' $ composed
1247−-- main = S.'drain' . 'parallely' $ composed
1235+-- main = S.'drain' . S.'parallely' $ composed
1250-- As an exercise try to figure out the output of this code for each mode of
1238-- As an exercise try to figure out the output of this code for each mode of
@@ -1257,7 +1245,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1257-- serial.
1245-- serial.
1260−-- import "Streamly"
1261-- import qualified "Streamly.Prelude" as S
1248-- import qualified "Streamly.Prelude" as S
1263-- main = (S.'toList' $ fmap show $ S.'fromFoldable' [1..10]) >>= print
1250-- main = (S.'toList' $ fmap show $ S.'fromFoldable' [1..10]) >>= print
@@ -1276,7 +1263,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1276-- serially and takes a total 17 seconds (1 + 3 + 4 + 2 + 3 + 4):
1263-- serially and takes a total 17 seconds (1 + 3 + 4 + 2 + 3 + 4):
1279−-- import "Streamly"
1280-- import qualified "Streamly.Prelude" as S
1266-- import qualified "Streamly.Prelude" as S
1281-- import Control.Concurrent
1267-- import Control.Concurrent
@@ -1284,7 +1270,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1284-- s2 = d 3 <> d 4
1270-- s2 = d 3 <> d 4
1285-- d n = delay n >> return n
1271-- d n = delay n >> return n
1287−-- main = (S.'toList' . 'serially' $ (,) \<$> s1 \<*> s2) >>= print
1273+-- main = (S.'toList' . S.'serially' $ (,) \<$> s1 \<*> s2) >>= print
1290-- ThreadId 36: Delay 1
1276-- ThreadId 36: Delay 1
@@ -1300,7 +1286,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1300-- order but since it is serial it takes a total of 17 seconds:
1286-- order but since it is serial it takes a total of 17 seconds:
1303−-- main = (S.'toList' . 'wSerially' $ (,) \<$> s1 \<*> s2) >>= print
1289+-- main = (S.'toList' . S.'wSerially' $ (,) \<$> s1 \<*> s2) >>= print
1306-- ThreadId 36: Delay 1
1292-- ThreadId 36: Delay 1
@@ -1316,7 +1302,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1316-- of 6 seconds which is max (1, 2) + max (3, 4):
1302-- of 6 seconds which is max (1, 2) + max (3, 4):
1319−-- main = (S.'toList' . 'asyncly' $ (,) \<$> s1 \<*> s2) >>= print
1305+-- main = (S.'toList' . S.'asyncly' $ (,) \<$> s1 \<*> s2) >>= print
1322-- ThreadId 34: Delay 1
1308-- ThreadId 34: Delay 1
@@ -1332,7 +1318,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1332-- therefore takes a total of 6 seconds (2 + 4):
1318-- therefore takes a total of 6 seconds (2 + 4):
1335−-- main = (S.'toList' . 'wAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
1321+-- main = (S.'toList' . S.'wAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
1338-- ThreadId 34: Delay 1
1324-- ThreadId 34: Delay 1
@@ -1360,15 +1346,14 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1360-- zip composition:
1346-- zip composition:
1363−-- import "Streamly"
1364-- import qualified "Streamly.Prelude" as S
1349-- import qualified "Streamly.Prelude" as S
1365-- import Control.Concurrent
1350-- import Control.Concurrent
1367-- d n = delay n >> return n
1352-- d n = delay n >> return n
1368−-- s1 = 'serially' $ d 1 <> d 2
1353+-- s1 = S.'serially' $ d 1 <> d 2
1369−-- s2 = 'serially' $ d 3 <> d 4
1354+-- s2 = S.'serially' $ d 3 <> d 4
1371−-- main = (S.'toList' . 'zipSerially' $ (,) \<$> s1 \<*> s2) >>= print
1356+-- main = (S.'toList' . S.'zipSerially' $ (,) \<$> s1 \<*> s2) >>= print
1374-- This takes total 10 seconds to zip, which is (1 + 2 + 3 + 4) since
1359-- This takes total 10 seconds to zip, which is (1 + 2 + 3 + 4) since
@@ -1390,18 +1375,17 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1393−-- import "Streamly"
1394-- import qualified "Streamly.Prelude" as S
1378-- import qualified "Streamly.Prelude" as S
1395-- import Control.Concurrent
1379-- import Control.Concurrent
1396-- import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
1380-- import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
1398-- d n = delay n >> return n
1382-- d n = delay n >> return n
1399−-- s1 = 'serially' $ d 1 <> d 2
1383+-- s1 = S.'serially' $ d 1 <> d 2
1400−-- s2 = 'serially' $ d 3 <> d 4
1384+-- s2 = S.'serially' $ d 3 <> d 4
1402-- main = do
1386-- main = do
1403-- hSetBuffering stdout LineBuffering
1387-- hSetBuffering stdout LineBuffering
1404−-- (S.'toList' . 'zipAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
1388+-- (S.'toList' . S.'zipAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
1407-- This takes 7 seconds to zip, which is max (1,3) + max (2,4) because 1 and 3
1391-- This takes 7 seconds to zip, which is max (1,3) + max (2,4) because 1 and 3
@@ -1432,17 +1416,16 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1432-- combinator instead of explicitly folding with 'async'.
1416-- combinator instead of explicitly folding with 'async'.
1435−-- import "Streamly"
1436-- import qualified "Streamly.Prelude" as S
1419-- import qualified "Streamly.Prelude" as S
1437-- import Data.List (sum)
1420-- import Data.List (sum)
1439-- main = do
1422-- main = do
1440-- z \<- S.'toList'
1423-- z \<- S.'toList'
1441−-- $ 'serially' -- Serial monadic processing (sqrt below)
1424+-- $ S.'serially' -- Serial monadic processing (sqrt below)
1443−-- x2 \<- 'forEachWith' 'async' [1..100] $ -- Concurrent @"for"@ loop
1426+-- x2 \<- S.'concatForFoldableWith' S.'async' [1..100] $ -- Concurrent @"for"@ loop
1444-- \\x -> return $ x * x -- body of the loop
1427-- \\x -> return $ x * x -- body of the loop
1445−-- y2 \<- 'forEachWith' 'async' [1..100] $
1428+-- y2 \<- S.'concatForFoldableWith' S.'async' [1..100] $
1446-- \\y -> return $ y * y
1429-- \\y -> return $ y * y
1447-- return $ sqrt (x2 + y2)
1430-- return $ sqrt (x2 + y2)
1448-- print $ sum z
1431-- print $ sum z
@@ -1477,11 +1460,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1478-- {-\# LANGUAGE FlexibleContexts #-}
1461-- {-\# LANGUAGE FlexibleContexts #-}
1480−-- import "Streamly"
1463+-- import "Streamly.Prelude" (MonadAsync, SerialT)
1481-- import "Streamly.Prelude" as S
1464-- import "Streamly.Prelude" as S
1482−-- import Control.Monad (void, when)
1465+-- import Control.Monad (void)
1483-- import Control.Monad.IO.Class (MonadIO(liftIO))
1466-- import Control.Monad.IO.Class (MonadIO(liftIO))
1484−-- import Control.Monad.State (MonadState, get, modify, runStateT, put)
1467+-- import Control.Monad.State (MonadState, get, modify, runStateT)
1486-- data Event = Quit | Harm Int | Heal Int deriving (Show)
1469-- data Event = Quit | Harm Int | Heal Int deriving (Show)
@@ -1497,13 +1480,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1497-- _ -> putStrLn "Type potion or harm or quit" >> askUser
1480-- _ -> putStrLn "Type potion or harm or quit" >> askUser
1499-- acidRain :: MonadAsync m => 'SerialT' m Event
1482-- acidRain :: MonadAsync m => 'SerialT' m Event
1500−-- acidRain = 'asyncly' $ 'constRate' 1 $ S.'repeatM' $ liftIO $ return $ Harm 1
1483+-- acidRain = S.'asyncly' $ S.'constRate' 1 $ S.'repeatM' $ liftIO $ return $ Harm 1
1502-- data Result = Check | Done
1485-- data Result = Check | Done
1504-- runEvents :: (MonadAsync m, MonadState Int m) => 'SerialT' m Result
1487-- runEvents :: (MonadAsync m, MonadState Int m) => 'SerialT' m Result
1505-- runEvents = do
1488-- runEvents = do
1506−-- event \<- userAction \`parallel` acidRain
1489+-- event \<- userAction \`S.'parallel'` acidRain
1507-- case event of
1490-- case event of
1508-- Harm n -> modify (\\h -> h - n) >> return Check
1491-- Harm n -> modify (\\h -> h - n) >> return Check
1509-- Heal n -> modify (\\h -> h + n) >> return Check
1492-- Heal n -> modify (\\h -> h + n) >> return Check
@@ -1556,12 +1539,12 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1556-- Interop with @vector@:
1539-- Interop with @vector@:
1559−-- import Streamly
1542+-- import "Streamly.Prelude" (SerialT)
1560−-- import qualified Streamly.Prelude as S
1543+-- import qualified "Streamly.Prelude" as S
1561-- import qualified Data.Vector.Fusion.Stream.Monadic as V
1544-- import qualified Data.Vector.Fusion.Stream.Monadic as V
1563-- -- | vector to streamly
1546-- -- | vector to streamly
1564−-- fromVector :: (IsStream t, Monad m) => V.Stream m a -> t m a
1547+-- fromVector :: (S.IsStream t, Monad m) => V.Stream m a -> t m a
1565-- fromVector = S.unfoldrM unconsV
1548-- fromVector = S.unfoldrM unconsV
1567-- unconsV v = do
1550-- unconsV v = do
@@ -1574,7 +1557,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1575-- -- | streamly to vector
1558-- -- | streamly to vector
1576-- toVector :: Monad m => SerialT m a -> V.Stream m a
1559-- toVector :: Monad m => SerialT m a -> V.Stream m a
1577−-- toVector = V.unfoldrM (S.uncons . adapt)
1560+-- toVector = V.unfoldrM (S.uncons . S.adapt)
1579-- main = do
1562-- main = do
1580-- S.toList (fromVector (V.fromList [1..3])) >>= print
1563-- S.toList (fromVector (V.fromList [1..3])) >>= print
@@ -1584,13 +1567,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1584-- Interop with @pipes@:
1567-- Interop with @pipes@:
1587−-- import "Streamly"
1570+-- import "Streamly.Prelude" (SerialT)
1588-- import qualified "Streamly.Prelude" as S
1571-- import qualified "Streamly.Prelude" as S
1589-- import qualified Pipes as P
1572-- import qualified Pipes as P
1590-- import qualified Pipes.Prelude as P
1573-- import qualified Pipes.Prelude as P
1592-- -- | pipes to streamly
1575-- -- | pipes to streamly
1593−-- fromPipes :: (IsStream t, Monad m) => P.Producer a m r -> t m a
1576+-- fromPipes :: (S.IsStream t, Monad m) => P.Producer a m r -> t m a
1594-- fromPipes = S.'unfoldrM' unconsP
1577-- fromPipes = S.'unfoldrM' unconsP
1596-- -- Adapt P.next to return a Maybe instead of Either
1579-- -- Adapt P.next to return a Maybe instead of Either
@@ -1611,7 +1594,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1611-- Interop with @streaming@:
1594-- Interop with @streaming@:
1614−-- import "Streamly"
1597+-- import "Streamly.Prelude" (SerialT, MonadAsync)
1615-- import qualified "Streamly.Prelude" as S
1598-- import qualified "Streamly.Prelude" as S
1616-- import qualified Streaming as SG
1599-- import qualified Streaming as SG
1617-- import qualified Streaming.Prelude as SG
1600-- import qualified Streaming.Prelude as SG
@@ -1635,7 +1618,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1635-- Interop with @conduit@:
1618-- Interop with @conduit@:
1638−-- import "Streamly"
1621+-- import "Streamly.Prelude" (SerialT)
1639-- import qualified "Streamly.Prelude" as S
1622-- import qualified "Streamly.Prelude" as S
1640-- import qualified Data.Conduit as C
1623-- import qualified Data.Conduit as C
1641-- import qualified Data.Conduit.List as C
1624-- import qualified Data.Conduit.List as C