@@ -263,6 +263,9 @@ import Prelude hiding
266+-- >>> import Control.Concurrent (threadDelay)
267+-- >>> import Data.Function ((&))
268+-- >>> import Streamly.Prelude ((|$))
266-- >>> import Prelude hiding ( filter, drop, dropWhile, take, takeWhile, foldr, map, mapM, sequence, reverse, foldr1 , scanl, scanl1)
269-- >>> import Prelude hiding ( filter, drop, dropWhile, take, takeWhile, foldr, map, mapM, sequence, reverse, foldr1 , scanl, scanl1)
267-- >>> import qualified Streamly.Prelude as Stream
270-- >>> import qualified Streamly.Prelude as Stream
268-- >>> import Streamly.Internal.Data.Stream.IsStream as Stream
271-- >>> import Streamly.Internal.Data.Stream.IsStream as Stream
@@ -287,7 +290,7 @@ transform pipe xs = fromStreamD $ D.transform pipe (toStreamD xs)
288-- | Right fold to a streaming monad.
291-- | Right fold to a streaming monad.
290−-- > foldrS S.cons S.nil === id
293+-- > foldrS Stream.cons Stream.nil === id
292-- 'foldrS' can be used to perform stateless stream to stream transformations
295-- 'foldrS' can be used to perform stateless stream to stream transformations
293-- like map and filter in general. It can be coupled with a scan to perform
296-- 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)
346-- the output of the resulting action.
349-- the output of the resulting action.
349−-- > drain $ S.mapM putStr $ S.fromList ["a", "b", "c"]
352+-- >>> drain $ Stream.mapM putStr $ Stream.fromList ["a", "b", "c"]
352−-- drain $ S.replicateM 10 (return 1)
356+-- drain $ Stream.replicateM 10 (return 1)
353−-- & (fromSerial . S.mapM (\\x -> threadDelay 1000000 >> print x))
357+-- & (fromSerial . Stream.mapM (\x -> threadDelay 1000000 >> print x))
355−-- drain $ S.replicateM 10 (return 1)
363+-- > drain $ Stream.replicateM 10 (return 1)
356−-- & (fromAsync . S.mapM (\\x -> threadDelay 1000000 >> print x))
364+-- & (fromAsync . Stream.mapM (\x -> threadDelay 1000000 >> print x))
359-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
367-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@@ -377,14 +385,25 @@ mapMSerial = Serial.mapM
377-- those actions.
385-- those actions.
380−-- > drain $ S.sequence $ S.fromList [putStr "a", putStr "b", putStrLn "c"]
388+-- >>> drain $ Stream.sequence $ Stream.fromList [putStr "a", putStr "b", putStrLn "c"]
383−-- drain $ S.replicateM 10 (return $ threadDelay 1000000 >> print 1)
392+-- drain $ Stream.replicateM 10 (return $ threadDelay 1000000 >> print 1)
384−-- & (fromSerial . S.sequence)
393+-- & (fromSerial . Stream.sequence)
400+-- drain $ Stream.replicateM 10 (return $ threadDelay 1000000 >> print 1)
401+-- & (fromAsync . Stream.sequence)
386−-- drain $ S.replicateM 10 (return $ threadDelay 1000000 >> print 1)
387−-- & (fromAsync . S.sequence)
390-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
409-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@@ -451,9 +470,10 @@ tapOffsetEvery offset n f xs =
454−-- > S.drain $ S.tapAsync (S.mapM_ print) (S.enumerateFromTo 1 2)
473+-- >>> Stream.drain $ Stream.tapAsync (Fold.drainBy print) (Stream.enumerateFromTo 1 2)
459-- Exceptions from the concurrently running fold are propagated to the current
479-- 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)
479-- For example, to print the count of elements processed every second:
499-- For example, to print the count of elements processed every second:
482−-- > S.drain $ S.pollCounts (const True) (S.rollingMap (-) . S.delayPost 1) (FL.drainBy print)
502+-- > Stream.drain $ Stream.pollCounts (const True) (Stream.rollingMap (-) . Stream.delayPost 1) (FLold.drainBy print)
483−-- $ S.enumerateFrom 0
503+-- $ Stream.enumerateFrom 0
486-- Note: This may not work correctly on 32-bit machines.
506-- Note: This may not work correctly on 32-bit machines.
@@ -509,9 +529,10 @@ pollCounts predicate transf f xs =
511-- > delay n = threadDelay (round $ n * 1000000) >> return n
531-- > 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)
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)
513−-- 2 elements processed
533+-- "2 elements processed"
514−-- 1 elements processed
535+-- "1 elements processed"
517-- Note: This may not work correctly on 32-bit machines.
538-- 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
530-- discard the results.
551-- discard the results.
533−-- > S.drain $ S.trace print (S.enumerateFromTo 1 2)
554+-- >>> Stream.drain $ Stream.trace print (Stream.enumerateFromTo 1 2)
538-- Compare with 'tap'.
560-- Compare with 'tap'.
@@ -546,9 +568,10 @@ trace f = mapM (\x -> void (f x) >> return x)
546-- discard the results.
568-- discard the results.
549−-- > S.drain $ S.trace_ (print "got here") (S.enumerateFromTo 1 2)
571+-- >>> Stream.drain $ Stream.trace_ (print "got here") (Stream.enumerateFromTo 1 2)
550-- "got here"
572-- "got here"
551-- "got here"
573-- "got here"
554-- Same as 'interspersePrefix_' but always serial.
577-- Same as 'interspersePrefix_' but always serial.
@@ -643,13 +666,15 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
643-- however it adds an extra element.
666-- however it adds an extra element.
646−-- > S.toList $ S.scanl' (+) 0 $ fromList [1,2,3,4]
669+-- >>> Stream.toList $ Stream.scanl' (+) 0 $ fromList [1,2,3,4]
647-- [0,1,3,6,10]
670-- [0,1,3,6,10]
651−-- > S.toList $ S.scanl' (flip (:)) [] $ S.fromList [1,2,3,4]
675+-- >>> Stream.toList $ Stream.scanl' (flip (:)) [] $ Stream.fromList [1,2,3,4]
652-- [[],[1],[2,1],[3,2,1],[4,3,2,1]]
676-- [[],[1],[2,1],[3,2,1],[4,3,2,1]]
655-- The output of 'scanl'' is the initial value of the accumulator followed by
680-- 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
665-- of the elements in a stream in one go using a @foldl'@:
690-- of the elements in a stream in one go using a @foldl'@:
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]
669-- (10,24)
694-- (10,24)
672-- Using @scanl'@ we can make it modular by computing the sum in the first
698-- Using @scanl'@ we can make it modular by computing the sum in the first
673-- stage and passing it down to the next stage for computing the product:
699-- stage and passing it down to the next stage for computing the product:
676−-- > S.foldl' (\\(_, p) (s, x) -> (s, p * x)) (0,1)
703+-- Stream.foldl' (\(_, p) (s, x) -> (s, p * x)) (0,1)
677−-- $ S.scanl' (\\(s, _) x -> (s + x, x)) (0,1)
704+-- $ Stream.scanl' (\(s, _) x -> (s + x, x)) (0,1)
678−-- $ S.fromList \[1,2,3,4]
705+-- $ Stream.fromList [1,2,3,4]
679-- (10,24)
707-- (10,24)
682-- IMPORTANT: 'scanl'' evaluates the accumulator to WHNF. To avoid building
711-- 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
693-- | Like 'scanl'' but does not stream the initial value of the accumulator.
722-- | Like 'scanl'' but does not stream the initial value of the accumulator.
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
697-- @since 0.7.0
726-- @since 0.7.0
698{-# INLINE postscanl' #-}
727{-# INLINE postscanl' #-}
@@ -730,8 +759,9 @@ scanl1M' step m = fromStreamD $ D.scanl1M' step $ toStreamD m
730-- is empty.
759-- is empty.
733−-- > S.toList $ S.scanl1 (+) $ fromList [1,2,3,4]
762+-- >>> Stream.toList $ Stream.scanl1' (+) $ fromList [1,2,3,4]
734-- [1,3,6,10]
763-- [1,3,6,10]
737-- @since 0.6.0
767-- @since 0.6.0
@@ -821,8 +851,9 @@ uniq = fromStreamD . D.uniq . toStreamD
824−-- > Stream.pruneBy isSpace (Stream.fromList " hello world! ")
854+-- > Stream.prune isSpace (Stream.fromList " hello world! ")
825-- "hello world!"
855-- "hello world!"
828-- Space: @O(1)@
859-- Space: @O(1)@
@@ -880,8 +911,9 @@ nubWindowBy = undefined -- fromStreamD . D.nubWithinBy . toStreamD
880-- the given equality predicate.
911-- the given equality predicate.
883−-- > S.toList $ S.deleteBy (==) 3 $ S.fromList [1,3,3,5]
914+-- >>> Stream.toList $ Stream.deleteBy (==) 3 $ Stream.fromList [1,3,3,5]
884-- [1,3,5]
915-- [1,3,5]
887-- @since 0.6.0
919-- @since 0.6.0
@@ -1096,8 +1128,9 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
1099−-- > S.toList $ S.insertBy compare 2 $ S.fromList [1,3,5]
1131+-- >>> Stream.toList $ Stream.insertBy compare 2 $ Stream.fromList [1,3,5]
1100-- [1,2,3,5]
1132-- [1,2,3,5]
1103-- @since 0.6.0
1136-- @since 0.6.0
@@ -1131,8 +1164,9 @@ intersperseM_ m = fromStreamD . D.intersperseM_ m . toStreamD
1131-- elements.
1164-- elements.
1134−-- > S.toList $ S.intersperseBySpan 2 (return ',') $ S.fromList "hello"
1167+-- > Stream.toList $ Stream.intersperseBySpan 2 (return ',') $ Stream.fromList "hello"
1135-- "he,ll,o"
1168-- "he,ll,o"
1138-- /Unimplemented/
1172-- /Unimplemented/
@@ -1154,7 +1188,9 @@ intersperseSuffix m = fromStreamD . D.intersperseSuffix m . toStreamD
1154-- | Insert a side effect after consuming an element of a stream.
1188-- | Insert a side effect after consuming an element of a stream.
1157−-- > S.mapM_ putChar $ S.intersperseSuffix_ (threadDelay 1000000) $ S.fromList "hello"
1191+-- >>> Stream.mapM_ putChar $ Stream.intersperseSuffix_ (threadDelay 1000000) $ Stream.fromList "hello"
1160-- /Pre-release/
1196-- /Pre-release/
@@ -1270,8 +1306,8 @@ reassembleBy = undefined
1270------------------------------------------------------------------------------
1306------------------------------------------------------------------------------
1273−-- > indexed = S.postscanl' (\(i, _) x -> (i + 1, x)) (-1,undefined)
1309+-- > indexed = Stream.postscanl' (\(i, _) x -> (i + 1, x)) (-1,undefined)
1274−-- > indexed = S.zipWith (,) (S.enumerateFrom 0)
1310+-- > indexed = Stream.zipWith (,) (Stream.enumerateFrom 0)
1276-- Pair each element in a stream with its index, starting from index 0.
1312-- Pair each element in a stream with its index, starting from index 0.
@@ -1284,8 +1320,8 @@ indexed :: (IsStream t, Monad m) => t m a -> t m (Int, a)
1284indexed = fromStreamD . D.indexed . toStreamD
1320indexed = fromStreamD . D.indexed . toStreamD
1287−-- > indexedR n = S.postscanl' (\(i, _) x -> (i - 1, x)) (n + 1,undefined)
1323+-- > indexedR n = Stream.postscanl' (\(i, _) x -> (i - 1, x)) (n + 1,undefined)
1288−-- > indexedR n = S.zipWith (,) (S.enumerateFromThen n (n - 1))
1324+-- > indexedR n = Stream.zipWith (,) (Stream.enumerateFromThen n (n - 1))
1290-- Pair each element in a stream with its index, starting from the
1326-- Pair each element in a stream with its index, starting from the
1291-- given index @n@ and counting down.
1327-- given index @n@ and counting down.
@@ -1307,7 +1343,7 @@ indexedR n = fromStreamD . D.indexedR n . toStreamD
1307-- If we do not do that then the following example will generate the same
1343-- If we do not do that then the following example will generate the same
1308-- timestamp for first two elements:
1344-- timestamp for first two elements:
1310−-- S.mapM_ print $ S.timestamped $ S.delay $ S.enumerateFromTo 1 3
1346+-- Stream.mapM_ print $ Stream.timestamped $ Stream.delay $ Stream.enumerateFromTo 1 3
1312-- | Pair each element in a stream with an absolute timestamp, using a clock of
1348-- | Pair each element in a stream with an absolute timestamp, using a clock of
1313-- specified granularity. The timestamp is generated just before the element
1349-- specified granularity. The timestamp is generated just before the element
@@ -1416,7 +1452,7 @@ rollingMapM f m = fromStreamD $ D.rollingMapM f $ toStreamD m
1416-- Equivalent to:
1452-- Equivalent to:
1419−-- mapMaybe f = S.map 'fromJust' . S.filter 'isJust' . S.map f
1455+-- mapMaybe f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.map f
1422-- @since 0.3.0
1458-- @since 0.3.0
@@ -1429,7 +1465,7 @@ mapMaybe f m = fromStreamS $ S.mapMaybe f $ toStreamS m
1429-- Equivalent to:
1465-- Equivalent to:
1432−-- mapMaybeM f = S.map 'fromJust' . S.filter 'isJust' . S.mapM f
1468+-- mapMaybeM f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.mapM f
1435-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
1471-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@@ -1489,8 +1525,6 @@ rights = fmap (fromRight undefined) . filter isRight
1489-- 1 second delay.
1525-- 1 second delay.
1492−-- >>> import Control.Concurrent (threadDelay)
1493−-- >>> import Streamly.Prelude ((|$))
1494-- >>> :{
1528-- >>> :{
1495-- Stream.drain $
1529-- Stream.drain $
1496-- Stream.mapM (\x -> threadDelay 1000000 >> print x)
1530-- Stream.mapM (\x -> threadDelay 1000000 >> print x)