@@ -170,7 +170,6 @@ module Streamly.Tutorial
170170 )
171171where
172172
173−import Streamly hiding (foldWith, foldMapWith, forEachWith)
174173import Streamly.Prelude
175174import Data.Semigroup
176175import Control.Applicative
@@ -345,8 +344,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
345344-- GHCi session and import these lines to start playing.
346345--
347346-- @
348−-- > import "Streamly"
349−-- > import "Streamly.Prelude" ((|:))
347+-- > import "Streamly.Prelude" ((|:), (|&))
350348-- > import qualified "Streamly.Prelude" as S
351349--
352350-- > import Control.Concurrent
@@ -412,15 +410,19 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
412410--
413411-- @
414412-- > let p n = threadDelay (n * 1000000) >> return n
415−-- > S.'toList' $ 'parallely' $ p 3 |: p 2 |: p 1 |: S.'nil'
413+-- > :set +s
414+-- > S.'toList' $ S.'parallely' $ p 3 |: p 2 |: p 1 |: S.'nil'
416415-- [1,2,3]
417−-- > S.'toList' $ 'aheadly' $ p 3 |: p 2 |: p 1 |: S.'nil'
416+-- (3.01 secs, 2,018,432 bytes)
417+-- > S.'toList' $ S.'aheadly' $ p 3 |: p 2 |: p 1 |: S.'nil'
418418-- [3,2,1]
419+-- (3.01 secs, 2,055,880 bytes)
419420-- @
420421-- The following finishes in 10 seconds (100 seconds when serial):
421422--
422423-- @
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)
424426-- @
425427--
426428
@@ -456,7 +458,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
456458-- numbers them and prints them:
457459--
458460-- @
459−-- import "Streamly"
460461-- import qualified "Streamly.Prelude" as S
461462-- import Data.Char (toUpper)
462463-- import Data.Function ((&))
@@ -482,7 +483,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
482483--
483484-- @
484485-- > 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))
486487-- @
487488--
488489
@@ -515,7 +516,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
515516-- not explicitly specified use the imports shown below.
516517--
517518-- @
518−-- import "Streamly"
519519-- import "Streamly.Prelude" ((|:), nil)
520520-- import qualified "Streamly.Prelude" as S
521521--
@@ -553,7 +553,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
553553-- 3, 4:
554554--
555555-- @
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)
557557-- @
558558-- @
559559-- 1
@@ -580,7 +580,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
580580-- irrespective of the type of stream:
581581--
582582-- @
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)
584584-- @
585585
586586-- $interleaved
@@ -597,7 +597,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
597597-- The following example prints the sequence 1, 3, 2, 4
598598--
599599-- @
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')
601601-- @
602602-- @
603603-- 1
@@ -612,7 +612,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
612612-- thread and take a combined total of @3 + 2 + 1 = 6@ seconds:
613613--
614614-- @
615−-- main = S.'drain' . 'wSerially' $ delay 3 <> delay 2 <> delay 1
615+-- main = S.'drain' . S.'wSerially' $ delay 3 <> delay 2 <> delay 1
616616-- @
617617-- @
618618-- ThreadId 36: Delay 3
@@ -626,7 +626,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
626626-- combinator in the following example:
627627--
628628-- @
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')
630630-- @
631631-- @
632632-- 1
@@ -656,7 +656,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
656656--
657657-- @
658658-- 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)
660660-- print xs
661661-- where p n = threadDelay 1000000 >> return n
662662-- @
@@ -693,7 +693,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
693693--
694694-- @
695695-- 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')
697697-- print xs
698698-- where p n = threadDelay 1000000 >> return n
699699-- @
@@ -708,7 +708,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
708708--
709709-- @
710710-- 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')
712712-- print xs
713713-- where p n = threadDelay 1000000 >> return n
714714-- @
@@ -722,7 +722,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
722722-- (3, 2, 1) = 3@ seconds:
723723--
724724-- @
725−-- main = S.'drain' . 'asyncly' $ delay 3 '<>' delay 2 '<>' delay 1
725+-- main = S.'drain' . S.'asyncly' $ delay 3 '<>' delay 2 '<>' delay 1
726726-- @
727727-- @
728728-- ThreadId 42: Delay 1
@@ -741,7 +741,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
741741-- second as all of the actions are concurrent.
742742--
743743-- @
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)
745745-- @
746746-- @
747747-- 1
@@ -758,7 +758,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
758758-- even if none of them blocks:
759759--
760760-- @
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)
762762-- where traced m = S.'yieldM' (myThreadId >>= print) >> return m
763763-- @
764764-- @
@@ -776,7 +776,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
776776-- not used the 'asyncly' combinator in the following example:
777777--
778778-- @
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
780780-- @
781781-- @
782782-- ThreadId 42: Delay 1
@@ -819,7 +819,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
819819-- first traversal order but this is not guaranteed.
820820--
821821-- @
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')
823823-- @
824824-- @
825825-- 1
@@ -834,7 +834,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
834834-- the 'wAsyncly' combinator in the following example:
835835--
836836-- @
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
838838-- @
839839-- @
840840-- ThreadId 42: Delay 1
@@ -873,11 +873,10 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
873873-- package to run this example:
874874--
875875-- @
876−-- import "Streamly"
877876-- import qualified Streamly.Prelude as S
878877-- import Network.HTTP.Simple
879878--
880−-- main = S.'drain' . 'parallely' $ google \<> bing \<> duckduckgo
879+-- main = S.'drain' . S.'parallely' $ google \<> bing \<> duckduckgo
881880-- where
882881-- google = get "https://www.google.com/search?q=haskell"
883882-- bing = get "https://www.bing.com/search?q=haskell"
@@ -891,7 +890,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
891890-- 'parallely' combinator in the following example:
892891--
893892-- @
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
895894-- @
896895-- @
897896-- ThreadId 42: Delay 1
@@ -921,27 +920,26 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
921920-- style using 'fold' or 'foldMap'. We have also provided some fold utilities
922921-- to fold streams using the polymorphic combine operations:
923922--
924−-- * 'foldWith' is like 'fold', it folds a 'Foldable' container of streams
925−-- using the given composition operator.
926−-- * 'foldMapWith' is like 'foldMap', it folds like @foldWith@ but also maps a
927−-- function before folding.
928−-- * 'forEachWith' is like @foldMapwith@ but the container argument comes before
929−-- the function argument.
923+-- * 'concatFoldableWith' is like 'fold', it folds a 'Foldable' container of
924+-- streams using the given composition operator.
925+-- * 'concatMapFoldableWith' is like 'foldMap', it folds like
926+-- @concatFoldableWith@ but also maps a function before folding.
927+-- * 'concatForFoldableWith' is like @concatMapFoldableWith@ but the container
928+-- argument comes before the function argument.
930929--
931930-- All of the following are equivalent and start ten concurrent tasks each with
932931-- a delay from 1 to 10 seconds, resulting in the printing of each number every
933932-- second:
934933--
935934-- @
936−-- import "Streamly"
937935-- import qualified "Streamly.Prelude" as S
938936-- import Control.Concurrent
939937--
940938-- main = do
941−-- S.'drain' $ 'asyncly' $ foldMap delay [1..10]
942−-- S.'drain' $ S.'foldWith' 'async' (map delay [1..10])
943−-- S.'drain' $ S.'foldMapWith' 'async' delay [1..10]
944−-- S.'drain' $ S.'forEachWith' 'async' [1..10] delay
939+-- S.'drain' $ S.'asyncly' $ foldMap delay [1..10]
940+-- S.'drain' $ S.'concatFoldableWith' S.'async' (map delay [1..10])
941+-- S.'drain' $ S.'concatMapFoldableWith' S.'async' delay [1..10]
942+-- S.'drain' $ S.'concatForFoldableWith' S.'async' [1..10] delay
945943-- where delay n = S.'yieldM' $ threadDelay (n * 1000000) >> print n
946944-- @
947945
@@ -987,7 +985,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
987985-- instead.
988986--
989987-- @
990−-- import "Streamly"
991988-- import qualified "Streamly.Prelude" as S
992989--
993990-- main = S.'drain' $ do
@@ -1009,12 +1006,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10091006-- written like this:
10101007--
10111008-- @
1012−-- import "Streamly"
10131009-- import qualified "Streamly.Prelude" as S
10141010--
10151011-- import Control.Monad (forever)
10161012--
1017−-- main = S.'drain' $ forever $ S.yieldM getLine >>= S.yieldM . putStrLn
1013+-- main = S.'drain' $ forever $ S.'yieldM' getLine >>= S.'yieldM' . putStrLn
10181014-- @
10191015--
10201016-- When multiple streams are composed using this style they nest in a DFS
@@ -1023,7 +1019,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10231019-- loops in imperative programming.
10241020--
10251021-- @
1026−-- import "Streamly"
10271022-- import qualified "Streamly.Prelude" as S
10281023--
10291024-- main = S.'drain' $ do
@@ -1052,10 +1047,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10521047-- type of the stream as 'Ahead'.
10531048--
10541049-- @
1055−-- import "Streamly"
10561050-- import qualified "Streamly.Prelude" as S
10571051--
1058−-- comp = S.'toList' . 'aheadly' $ do
1052+-- comp = S.'toList' . S.'aheadly' $ do
10591053-- x <- S.'fromFoldable' [3,2,1]
10601054-- delay x >> return x
10611055--
@@ -1093,10 +1087,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
10931087-- type of the stream as 'Async'.
10941088--
10951089-- @
1096−-- import "Streamly"
10971090-- import qualified "Streamly.Prelude" as S
10981091--
1099−-- main = S.'drain' . 'asyncly' $ do
1092+-- main = S.'drain' . S.'asyncly' $ do
11001093-- x <- S.'fromFoldable' [3,2,1]
11011094-- delay x
11021095-- @
@@ -1120,10 +1113,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11201113-- on the demand from the consumer of the stream.
11211114--
11221115-- @
1123−-- import "Streamly"
11241116-- import qualified "Streamly.Prelude" as S
11251117--
1126−-- main = S.'drain' . 'asyncly' $ do
1118+-- main = S.'drain' . S.'asyncly' $ do
11271119-- x <- S.'fromFoldable' [1,2]
11281120-- y <- S.'fromFoldable' [3,4]
11291121-- S.'yieldM' $ putStrLn $ show (x, y)
@@ -1145,10 +1137,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11451137-- type of the stream as 'WSerial'.
11461138--
11471139-- @
1148−-- import "Streamly"
11491140-- import qualified "Streamly.Prelude" as S
11501141--
1151−-- main = S.'drain' . 'wSerially' $ do
1142+-- main = S.'drain' . S.'wSerially' $ do
11521143-- x <- S.'fromFoldable' [1,2]
11531144-- y <- S.'fromFoldable' [3,4]
11541145-- S.yieldM $ putStrLn $ show (x, y)
@@ -1173,10 +1164,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11731164-- specify the type of the stream as 'WAsync'.
11741165--
11751166-- @
1176−-- import "Streamly"
11771167-- import qualified "Streamly.Prelude" as S
11781168--
1179−-- main = S.'drain' . 'wAsyncly' $ do
1169+-- main = S.'drain' . S.'wAsyncly' $ do
11801170-- x <- S.'fromFoldable' [1,2]
11811171-- y <- S.'fromFoldable' [3,4]
11821172-- S.'yieldM' $ putStrLn $ show (x, y)
@@ -1199,10 +1189,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11991189-- annotation can be used to specify the type of the stream as 'Parallel'.
12001190--
12011191-- @
1202−-- import "Streamly"
12031192-- import qualified "Streamly.Prelude" as S
12041193--
1205−-- main = S.'drain' . 'parallely' $ do
1194+-- main = S.'drain' . S.'parallely' $ do
12061195-- x <- S.'fromFoldable' [3,2,1]
12071196-- delay x
12081197-- @
@@ -1220,10 +1209,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
12201209-- specific mode of composition. For example take a look at the following code.
12211210--
12221211-- @
1223−-- import "Streamly"
12241212-- import qualified "Streamly.Prelude" as S
12251213--
1226−-- composed :: (IsStream t, Monad (t IO)) => t IO ()
1214+-- composed :: (S.IsStream t, Monad (t IO)) => t IO ()
12271215-- composed = do
12281216-- sz <- sizes
12291217-- cl <- colors
@@ -1240,11 +1228,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
12401228-- Now we can interpret this in whatever way we want:
12411229--
12421230-- @
1243−-- main = S.'drain' . 'serially' $ composed
1244−-- main = S.'drain' . 'wSerially' $ composed
1245−-- main = S.'drain' . 'asyncly' $ composed
1246−-- main = S.'drain' . 'wAsyncly' $ composed
1247−-- main = S.'drain' . 'parallely' $ composed
1231+-- main = S.'drain' . S.'serially' $ composed
1232+-- main = S.'drain' . S.'wSerially' $ composed
1233+-- main = S.'drain' . S.'asyncly' $ composed
1234+-- main = S.'drain' . S.'wAsyncly' $ composed
1235+-- main = S.'drain' . S.'parallely' $ composed
12481236-- @
12491237--
12501238-- 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))
12571245-- serial.
12581246--
12591247-- @
1260−-- import "Streamly"
12611248-- import qualified "Streamly.Prelude" as S
12621249--
12631250-- main = (S.'toList' $ fmap show $ S.'fromFoldable' [1..10]) >>= print
@@ -1276,7 +1263,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
12761263-- serially and takes a total 17 seconds (1 + 3 + 4 + 2 + 3 + 4):
12771264--
12781265-- @
1279−-- import "Streamly"
12801266-- import qualified "Streamly.Prelude" as S
12811267-- import Control.Concurrent
12821268--
@@ -1284,7 +1270,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
12841270-- s2 = d 3 <> d 4
12851271-- d n = delay n >> return n
12861272--
1287−-- main = (S.'toList' . 'serially' $ (,) \<$> s1 \<*> s2) >>= print
1273+-- main = (S.'toList' . S.'serially' $ (,) \<$> s1 \<*> s2) >>= print
12881274-- @
12891275-- @
12901276-- ThreadId 36: Delay 1
@@ -1300,7 +1286,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
13001286-- order but since it is serial it takes a total of 17 seconds:
13011287--
13021288-- @
1303−-- main = (S.'toList' . 'wSerially' $ (,) \<$> s1 \<*> s2) >>= print
1289+-- main = (S.'toList' . S.'wSerially' $ (,) \<$> s1 \<*> s2) >>= print
13041290-- @
13051291-- @
13061292-- ThreadId 36: Delay 1
@@ -1316,7 +1302,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
13161302-- of 6 seconds which is max (1, 2) + max (3, 4):
13171303--
13181304-- @
1319−-- main = (S.'toList' . 'asyncly' $ (,) \<$> s1 \<*> s2) >>= print
1305+-- main = (S.'toList' . S.'asyncly' $ (,) \<$> s1 \<*> s2) >>= print
13201306-- @
13211307-- @
13221308-- ThreadId 34: Delay 1
@@ -1332,7 +1318,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
13321318-- therefore takes a total of 6 seconds (2 + 4):
13331319--
13341320-- @
1335−-- main = (S.'toList' . 'wAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
1321+-- main = (S.'toList' . S.'wAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
13361322-- @
13371323-- @
13381324-- ThreadId 34: Delay 1
@@ -1360,15 +1346,14 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
13601346-- zip composition:
13611347--
13621348-- @
1363−-- import "Streamly"
13641349-- import qualified "Streamly.Prelude" as S
13651350-- import Control.Concurrent
13661351--
13671352-- d n = delay n >> return n
1368−-- s1 = 'serially' $ d 1 <> d 2
1369−-- s2 = 'serially' $ d 3 <> d 4
1353+-- s1 = S.'serially' $ d 1 <> d 2
1354+-- s2 = S.'serially' $ d 3 <> d 4
13701355--
1371−-- main = (S.'toList' . 'zipSerially' $ (,) \<$> s1 \<*> s2) >>= print
1356+-- main = (S.'toList' . S.'zipSerially' $ (,) \<$> s1 \<*> s2) >>= print
13721357-- @
13731358--
13741359-- 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))
13901375--
13911376--
13921377-- @
1393−-- import "Streamly"
13941378-- import qualified "Streamly.Prelude" as S
13951379-- import Control.Concurrent
13961380-- import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
13971381--
13981382-- d n = delay n >> return n
1399−-- s1 = 'serially' $ d 1 <> d 2
1400−-- s2 = 'serially' $ d 3 <> d 4
1383+-- s1 = S.'serially' $ d 1 <> d 2
1384+-- s2 = S.'serially' $ d 3 <> d 4
14011385--
14021386-- main = do
14031387-- hSetBuffering stdout LineBuffering
1404−-- (S.'toList' . 'zipAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
1388+-- (S.'toList' . S.'zipAsyncly' $ (,) \<$> s1 \<*> s2) >>= print
14051389-- @
14061390--
14071391-- 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))
14321416-- combinator instead of explicitly folding with 'async'.
14331417--
14341418-- @
1435−-- import "Streamly"
14361419-- import qualified "Streamly.Prelude" as S
14371420-- import Data.List (sum)
14381421--
14391422-- main = do
14401423-- z \<- S.'toList'
1441−-- $ 'serially' -- Serial monadic processing (sqrt below)
1424+-- $ S.'serially' -- Serial monadic processing (sqrt below)
14421425-- $ do
1443−-- x2 \<- 'forEachWith' 'async' [1..100] $ -- Concurrent @"for"@ loop
1426+-- x2 \<- S.'concatForFoldableWith' S.'async' [1..100] $ -- Concurrent @"for"@ loop
14441427-- \\x -> return $ x * x -- body of the loop
1445−-- y2 \<- 'forEachWith' 'async' [1..100] $
1428+-- y2 \<- S.'concatForFoldableWith' S.'async' [1..100] $
14461429-- \\y -> return $ y * y
14471430-- return $ sqrt (x2 + y2)
14481431-- print $ sum z
@@ -1477,11 +1460,11 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
14771460-- @
14781461-- {-\# LANGUAGE FlexibleContexts #-}
14791462--
1480−-- import "Streamly"
1463+-- import "Streamly.Prelude" (MonadAsync, SerialT)
14811464-- import "Streamly.Prelude" as S
1482−-- import Control.Monad (void, when)
1465+-- import Control.Monad (void)
14831466-- 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)
14851468--
14861469-- data Event = Quit | Harm Int | Heal Int deriving (Show)
14871470--
@@ -1497,13 +1480,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
14971480-- _ -> putStrLn "Type potion or harm or quit" >> askUser
14981481--
14991482-- 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
15011484--
15021485-- data Result = Check | Done
15031486--
15041487-- runEvents :: (MonadAsync m, MonadState Int m) => 'SerialT' m Result
15051488-- runEvents = do
1506−-- event \<- userAction \`parallel` acidRain
1489+-- event \<- userAction \`S.'parallel'` acidRain
15071490-- case event of
15081491-- Harm n -> modify (\\h -> h - n) >> return Check
15091492-- Heal n -> modify (\\h -> h + n) >> return Check
@@ -1556,12 +1539,12 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
15561539-- Interop with @vector@:
15571540--
15581541-- @
1559−-- import Streamly
1560−-- import qualified Streamly.Prelude as S
1542+-- import "Streamly.Prelude" (SerialT)
1543+-- import qualified "Streamly.Prelude" as S
15611544-- import qualified Data.Vector.Fusion.Stream.Monadic as V
15621545--
15631546-- -- | 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
15651548-- fromVector = S.unfoldrM unconsV
15661549-- where
15671550-- unconsV v = do
@@ -1574,7 +1557,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
15741557--
15751558-- -- | streamly to vector
15761559-- 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)
15781561--
15791562-- main = do
15801563-- S.toList (fromVector (V.fromList [1..3])) >>= print
@@ -1584,13 +1567,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
15841567-- Interop with @pipes@:
15851568--
15861569-- @
1587−-- import "Streamly"
1570+-- import "Streamly.Prelude" (SerialT)
15881571-- import qualified "Streamly.Prelude" as S
15891572-- import qualified Pipes as P
15901573-- import qualified Pipes.Prelude as P
15911574--
15921575-- -- | 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
15941577-- fromPipes = S.'unfoldrM' unconsP
15951578-- where
15961579-- -- Adapt P.next to return a Maybe instead of Either
@@ -1611,7 +1594,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
16111594-- Interop with @streaming@:
16121595--
16131596-- @
1614−-- import "Streamly"
1597+-- import "Streamly.Prelude" (SerialT, MonadAsync)
16151598-- import qualified "Streamly.Prelude" as S
16161599-- import qualified Streaming as SG
16171600-- import qualified Streaming.Prelude as SG
@@ -1635,7 +1618,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
16351618-- Interop with @conduit@:
16361619--
16371620-- @
1638−-- import "Streamly"
1621+-- import "Streamly.Prelude" (SerialT)
16391622-- import qualified "Streamly.Prelude" as S
16401623-- import qualified Data.Conduit as C
16411624-- import qualified Data.Conduit.List as C