@@ -263,6 +263,9 @@ import Prelude hiding
263263--
264264-- $setup
265265-- >>> :m
266+-- >>> import Control.Concurrent (threadDelay)
267+-- >>> import Data.Function ((&))
268+-- >>> import Streamly.Prelude ((|$))
266269-- >>> import Prelude hiding ( filter, drop, dropWhile, take, takeWhile, foldr, map, mapM, sequence, reverse, foldr1 , scanl, scanl1)
267270-- >>> import qualified Streamly.Prelude as Stream
268271-- >>> import Streamly.Internal.Data.Stream.IsStream as Stream
@@ -287,7 +290,7 @@ transform pipe xs = fromStreamD $ D.transform pipe (toStreamD xs)
287290
288291-- | Right fold to a streaming monad.
289292--
290−-- > foldrS S.cons S.nil === id
293+-- > foldrS Stream.cons Stream.nil === id
291294--
292295-- 'foldrS' can be used to perform stateless stream to stream transformations
293296-- like map and filter in general. It can be coupled with a scan to perform
@@ -346,14 +349,19 @@ foldrT f z s = S.foldrT f z (toStreamS s)
346349-- the output of the resulting action.
347350--
348351-- @
349−-- > drain $ S.mapM putStr $ S.fromList ["a", "b", "c"]
352+-- >>> drain $ Stream.mapM putStr $ Stream.fromList ["a", "b", "c"]
350353-- abc
351354--
352−-- drain $ S.replicateM 10 (return 1)
353−-- & (fromSerial . S.mapM (\\x -> threadDelay 1000000 >> print x))
355+-- >>> :{
356+-- drain $ Stream.replicateM 10 (return 1)
357+-- & (fromSerial . Stream.mapM (\x -> threadDelay 1000000 >> print x))
358+-- :}
359+-- 1
360+-- ...
361+-- 1
354362--
355−-- drain $ S.replicateM 10 (return 1)
356−-- & (fromAsync . S.mapM (\\x -> threadDelay 1000000 >> print x))
363+-- > drain $ Stream.replicateM 10 (return 1)
364+-- & (fromAsync . Stream.mapM (\x -> threadDelay 1000000 >> print x))
357365-- @
358366--
359367-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@@ -377,14 +385,25 @@ mapMSerial = Serial.mapM
377385-- those actions.
378386--
379387-- @
380−-- > drain $ S.sequence $ S.fromList [putStr "a", putStr "b", putStrLn "c"]
388+-- >>> drain $ Stream.sequence $ Stream.fromList [putStr "a", putStr "b", putStrLn "c"]
381389-- abc
382390--
383−-- drain $ S.replicateM 10 (return $ threadDelay 1000000 >> print 1)
384−-- & (fromSerial . S.sequence)
391+-- >>> :{
392+-- drain $ Stream.replicateM 10 (return $ threadDelay 1000000 >> print 1)
393+-- & (fromSerial . Stream.sequence)
394+-- :}
395+-- 1
396+-- ...
397+-- 1
398+--
399+-- >>> :{
400+-- drain $ Stream.replicateM 10 (return $ threadDelay 1000000 >> print 1)
401+-- & (fromAsync . Stream.sequence)
402+-- :}
403+-- 1
404+-- ...
405+-- 1
385406--
386−-- drain $ S.replicateM 10 (return $ threadDelay 1000000 >> print 1)
387−-- & (fromAsync . S.sequence)
388407-- @
389408--
390409-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@@ -451,9 +470,10 @@ tapOffsetEvery offset n f xs =
451470-- @
452471--
453472-- @
454−-- > S.drain $ S.tapAsync (S.mapM_ print) (S.enumerateFromTo 1 2)
473+-- >>> Stream.drain $ Stream.tapAsync (Fold.drainBy print) (Stream.enumerateFromTo 1 2)
455474-- 1
456475-- 2
476+--
457477-- @
458478--
459479-- Exceptions from the concurrently running fold are propagated to the current
@@ -479,8 +499,8 @@ tapAsync f xs = D.fromStreamD $ Par.tapAsyncF f (D.toStreamD xs)
479499-- For example, to print the count of elements processed every second:
480500--
481501-- @
482−-- > S.drain $ S.pollCounts (const True) (S.rollingMap (-) . S.delayPost 1) (FL.drainBy print)
483−-- $ S.enumerateFrom 0
502+-- > Stream.drain $ Stream.pollCounts (const True) (Stream.rollingMap (-) . Stream.delayPost 1) (FLold.drainBy print)
503+-- $ Stream.enumerateFrom 0
484504-- @
485505--
486506-- Note: This may not work correctly on 32-bit machines.
@@ -509,9 +529,10 @@ pollCounts predicate transf f xs =
509529--
510530-- @
511531-- > delay n = threadDelay (round $ n * 1000000) >> return n
512−-- > S.drain $ S.tapRate 2 (\\n -> print $ show n ++ " elements processed") (delay 1 S.|: delay 0.5 S.|: delay 0.5 S.|: S.nil)
513−-- 2 elements processed
514−-- 1 elements processed
532+-- > Stream.toList $ Stream.tapRate 2 (\n -> print $ show n ++ " elements processed") (delay 1 Stream.|: delay 0.5 Stream.|: delay 0.5 Stream.|: Stream.nil)
533+-- "2 elements processed"
534+-- [1.0,0.5,0.5]
535+-- "1 elements processed"
515536-- @
516537--
517538-- Note: This may not work correctly on 32-bit machines.
@@ -530,9 +551,10 @@ tapRate n f xs = D.fromStreamD $ D.tapRate n f $ D.toStreamD xs
530551-- discard the results.
531552--
532553-- @
533−-- > S.drain $ S.trace print (S.enumerateFromTo 1 2)
554+-- >>> Stream.drain $ Stream.trace print (Stream.enumerateFromTo 1 2)
534555-- 1
535556-- 2
557+--
536558-- @
537559--
538560-- Compare with 'tap'.
@@ -546,9 +568,10 @@ trace f = mapM (\x -> void (f x) >> return x)
546568-- discard the results.
547569--
548570-- @
549−-- > S.drain $ S.trace_ (print "got here") (S.enumerateFromTo 1 2)
571+-- >>> Stream.drain $ Stream.trace_ (print "got here") (Stream.enumerateFromTo 1 2)
550572-- "got here"
551573-- "got here"
574+--
552575-- @
553576--
554577-- Same as 'interspersePrefix_' but always serial.
@@ -643,13 +666,15 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
643666-- however it adds an extra element.
644667--
645668-- @
646−-- > S.toList $ S.scanl' (+) 0 $ fromList [1,2,3,4]
669+-- >>> Stream.toList $ Stream.scanl' (+) 0 $ fromList [1,2,3,4]
647670-- [0,1,3,6,10]
671+--
648672-- @
649673--
650674-- @
651−-- > S.toList $ S.scanl' (flip (:)) [] $ S.fromList [1,2,3,4]
675+-- >>> Stream.toList $ Stream.scanl' (flip (:)) [] $ Stream.fromList [1,2,3,4]
652676-- [[],[1],[2,1],[3,2,1],[4,3,2,1]]
677+--
653678-- @
654679--
655680-- The output of 'scanl'' is the initial value of the accumulator followed by
@@ -665,18 +690,22 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
665690-- of the elements in a stream in one go using a @foldl'@:
666691--
667692-- @
668−-- > S.foldl' (\\(s, p) x -> (s + x, p * x)) (0,1) $ S.fromList \[1,2,3,4]
693+-- >>> Stream.foldl' (\(s, p) x -> (s + x, p * x)) (0,1) $ Stream.fromList [1,2,3,4]
669694-- (10,24)
695+--
670696-- @
671697--
672698-- Using @scanl'@ we can make it modular by computing the sum in the first
673699-- stage and passing it down to the next stage for computing the product:
674700--
675701-- @
676−-- > S.foldl' (\\(_, p) (s, x) -> (s, p * x)) (0,1)
677−-- $ S.scanl' (\\(s, _) x -> (s + x, x)) (0,1)
678−-- $ S.fromList \[1,2,3,4]
702+-- >>> :{
703+-- Stream.foldl' (\(_, p) (s, x) -> (s, p * x)) (0,1)
704+-- $ Stream.scanl' (\(s, _) x -> (s + x, x)) (0,1)
705+-- $ Stream.fromList [1,2,3,4]
706+-- :}
679707-- (10,24)
708+--
680709-- @
681710--
682711-- IMPORTANT: 'scanl'' evaluates the accumulator to WHNF. To avoid building
@@ -692,7 +721,7 @@ scanl' step z m = fromStreamS $ S.scanl' step z $ toStreamS m
692721
693722-- | Like 'scanl'' but does not stream the initial value of the accumulator.
694723--
695−-- > postscanl' f z xs = S.drop 1 $ S.scanl' f z xs
724+-- > postscanl' f z xs = Stream.drop 1 $ Stream.scanl' f z xs
696725--
697726-- @since 0.7.0
698727{-# INLINE postscanl' #-}
@@ -730,8 +759,9 @@ scanl1M' step m = fromStreamD $ D.scanl1M' step $ toStreamD m
730759-- is empty.
731760--
732761-- @
733−-- > S.toList $ S.scanl1 (+) $ fromList [1,2,3,4]
762+-- >>> Stream.toList $ Stream.scanl1' (+) $ fromList [1,2,3,4]
734763-- [1,3,6,10]
764+--
735765-- @
736766--
737767-- @since 0.6.0
@@ -821,8 +851,9 @@ uniq = fromStreamD . D.uniq . toStreamD
821851-- @
822852--
823853-- @
824−-- > Stream.pruneBy isSpace (Stream.fromList " hello world! ")
854+-- > Stream.prune isSpace (Stream.fromList " hello world! ")
825855-- "hello world!"
856+--
826857-- @
827858--
828859-- Space: @O(1)@
@@ -880,8 +911,9 @@ nubWindowBy = undefined -- fromStreamD . D.nubWithinBy . toStreamD
880911-- the given equality predicate.
881912--
882913-- @
883−-- > S.toList $ S.deleteBy (==) 3 $ S.fromList [1,3,3,5]
914+-- >>> Stream.toList $ Stream.deleteBy (==) 3 $ Stream.fromList [1,3,3,5]
884915-- [1,3,5]
916+--
885917-- @
886918--
887919-- @since 0.6.0
@@ -1096,8 +1128,9 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
10961128-- @
10971129--
10981130-- @
1099−-- > S.toList $ S.insertBy compare 2 $ S.fromList [1,3,5]
1131+-- >>> Stream.toList $ Stream.insertBy compare 2 $ Stream.fromList [1,3,5]
11001132-- [1,2,3,5]
1133+--
11011134-- @
11021135--
11031136-- @since 0.6.0
@@ -1131,8 +1164,9 @@ intersperseM_ m = fromStreamD . D.intersperseM_ m . toStreamD
11311164-- elements.
11321165--
11331166-- @
1134−-- > S.toList $ S.intersperseBySpan 2 (return ',') $ S.fromList "hello"
1167+-- > Stream.toList $ Stream.intersperseBySpan 2 (return ',') $ Stream.fromList "hello"
11351168-- "he,ll,o"
1169+--
11361170-- @
11371171--
11381172-- /Unimplemented/
@@ -1154,7 +1188,9 @@ intersperseSuffix m = fromStreamD . D.intersperseSuffix m . toStreamD
11541188-- | Insert a side effect after consuming an element of a stream.
11551189--
11561190-- @
1157−-- > S.mapM_ putChar $ S.intersperseSuffix_ (threadDelay 1000000) $ S.fromList "hello"
1191+-- >>> Stream.mapM_ putChar $ Stream.intersperseSuffix_ (threadDelay 1000000) $ Stream.fromList "hello"
1192+-- hello
1193+--
11581194-- @
11591195--
11601196-- /Pre-release/
@@ -1270,8 +1306,8 @@ reassembleBy = undefined
12701306------------------------------------------------------------------------------
12711307
12721308-- |
1273−-- > indexed = S.postscanl' (\(i, _) x -> (i + 1, x)) (-1,undefined)
1274−-- > indexed = S.zipWith (,) (S.enumerateFrom 0)
1309+-- > indexed = Stream.postscanl' (\(i, _) x -> (i + 1, x)) (-1,undefined)
1310+-- > indexed = Stream.zipWith (,) (Stream.enumerateFrom 0)
12751311--
12761312-- Pair each element in a stream with its index, starting from index 0.
12771313--
@@ -1284,8 +1320,8 @@ indexed :: (IsStream t, Monad m) => t m a -> t m (Int, a)
12841320indexed = fromStreamD . D.indexed . toStreamD
12851321
12861322-- |
1287−-- > indexedR n = S.postscanl' (\(i, _) x -> (i - 1, x)) (n + 1,undefined)
1288−-- > indexedR n = S.zipWith (,) (S.enumerateFromThen n (n - 1))
1323+-- > indexedR n = Stream.postscanl' (\(i, _) x -> (i - 1, x)) (n + 1,undefined)
1324+-- > indexedR n = Stream.zipWith (,) (Stream.enumerateFromThen n (n - 1))
12891325--
12901326-- Pair each element in a stream with its index, starting from the
12911327-- given index @n@ and counting down.
@@ -1307,7 +1343,7 @@ indexedR n = fromStreamD . D.indexedR n . toStreamD
13071343-- If we do not do that then the following example will generate the same
13081344-- timestamp for first two elements:
13091345--
1310−-- S.mapM_ print $ S.timestamped $ S.delay $ S.enumerateFromTo 1 3
1346+-- Stream.mapM_ print $ Stream.timestamped $ Stream.delay $ Stream.enumerateFromTo 1 3
13111347--
13121348-- | Pair each element in a stream with an absolute timestamp, using a clock of
13131349-- specified granularity. The timestamp is generated just before the element
@@ -1416,7 +1452,7 @@ rollingMapM f m = fromStreamD $ D.rollingMapM f $ toStreamD m
14161452-- Equivalent to:
14171453--
14181454-- @
1419−-- mapMaybe f = S.map 'fromJust' . S.filter 'isJust' . S.map f
1455+-- mapMaybe f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.map f
14201456-- @
14211457--
14221458-- @since 0.3.0
@@ -1429,7 +1465,7 @@ mapMaybe f m = fromStreamS $ S.mapMaybe f $ toStreamS m
14291465-- Equivalent to:
14301466--
14311467-- @
1432−-- mapMaybeM f = S.map 'fromJust' . S.filter 'isJust' . S.mapM f
1468+-- mapMaybeM f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.mapM f
14331469-- @
14341470--
14351471-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@@ -1489,8 +1525,6 @@ rights = fmap (fromRight undefined) . filter isRight
14891525-- 1 second delay.
14901526--
14911527--
1492−-- >>> import Control.Concurrent (threadDelay)
1493−-- >>> import Streamly.Prelude ((|$))
14941528-- >>> :{
14951529-- Stream.drain $
14961530-- Stream.mapM (\x -> threadDelay 1000000 >> print x)