on master help sign in
Use full module names in documentation
f95cb89Ranjeet Kumar Ranjan
src/Streamly/Internal/Data/Stream/IsStream/Enumeration.hs+49−24
@@ -78,10 +78,13 @@ import qualified Streamly.Internal.Data.Stream.Serial as Serial (map)
78-- check for overflow, underflow or bounds.
78-- check for overflow, underflow or bounds.
79--
79--
80-- @
80-- @
81+-- >>> import Streamly.Internal.Data.Stream.IsStream.Enumeration as Stream
81−-- > S.toList $ S.take 4 $ S.enumerateFromStepIntegral 0 2
82+-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromStepIntegral 0 2
82-- [0,2,4,6]
83-- [0,2,4,6]
84+--
83−-- > S.toList $ S.take 3 $ S.enumerateFromStepIntegral 0 (-2)
85+-- >>> Stream.toList $ Stream.take 3 $ Stream.enumerateFromStepIntegral 0 (-2)
84-- [0,-2,-4]
86-- [0,-2,-4]
87+--
85-- @
88-- @
86--
89--
87-- @since 0.6.0
90-- @since 0.6.0
@@ -97,8 +100,9 @@ enumerateFromStepIntegral from stride =
97-- increments of @1@. The stream is bounded by the size of the 'Integral' type.
100-- increments of @1@. The stream is bounded by the size of the 'Integral' type.
98--
101--
99-- @
102-- @
100−-- > S.toList $ S.take 4 $ S.enumerateFromIntegral (0 :: Int)
103+-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromIntegral (0 :: Int)
101-- [0,1,2,3]
104-- [0,1,2,3]
105+--
102-- @
106-- @
103--
107--
104-- @since 0.6.0
108-- @since 0.6.0
@@ -114,10 +118,12 @@ enumerateFromIntegral from = fromStreamD $ D.enumerateFromIntegral from
114-- The stream is bounded by the size of the 'Integral' type.
118-- The stream is bounded by the size of the 'Integral' type.
115--
119--
116-- @
120-- @
117−-- > S.toList $ S.take 4 $ S.enumerateFromThenIntegral (0 :: Int) 2
121+-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenIntegral (0 :: Int) 2
118-- [0,2,4,6]
122-- [0,2,4,6]
123+--
119−-- > S.toList $ S.take 4 $ S.enumerateFromThenIntegral (0 :: Int) (-2)
124+-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenIntegral (0 :: Int) (-2)
120-- [0,-2,-4,-6]
125-- [0,-2,-4,-6]
126+--
121-- @
127-- @
122--
128--
123-- @since 0.6.0
129-- @since 0.6.0
@@ -134,8 +140,9 @@ enumerateFromThenIntegral from next =
134-- @to@.
140-- @to@.
135--
141--
136-- @
142-- @
137−-- > S.toList $ S.enumerateFromToIntegral 0 4
143+-- >>> Stream.toList $ Stream.enumerateFromToIntegral 0 4
138-- [0,1,2,3,4]
144-- [0,1,2,3,4]
145+--
139-- @
146-- @
140--
147--
141-- @since 0.6.0
148-- @since 0.6.0
@@ -150,10 +157,12 @@ enumerateFromToIntegral from to =
150-- elements are in increments of @then - from@ up to @to@.
157-- elements are in increments of @then - from@ up to @to@.
151--
158--
152-- @
159-- @
153−-- > S.toList $ S.enumerateFromThenToIntegral 0 2 6
160+-- >>> Stream.toList $ Stream.enumerateFromThenToIntegral 0 2 6
154-- [0,2,4,6]
161-- [0,2,4,6]
162+--
155−-- > S.toList $ S.enumerateFromThenToIntegral 0 (-2) (-6)
163+-- >>> Stream.toList $ Stream.enumerateFromThenToIntegral 0 (-2) (-6)
156-- [0,-2,-4,-6]
164-- [0,-2,-4,-6]
165+--
157-- @
166-- @
158--
167--
159-- @since 0.6.0
168-- @since 0.6.0
@@ -181,8 +190,9 @@ enumerateFromThenToIntegral from next to =
181-- This is the equivalent to 'enumFrom' for 'Fractional' types. For example:
190-- This is the equivalent to 'enumFrom' for 'Fractional' types. For example:
182--
191--
183-- @
192-- @
184−-- > S.toList $ S.take 4 $ S.enumerateFromFractional 1.1
193+-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromFractional 1.1
185-- [1.1,2.1,3.1,4.1]
194-- [1.1,2.1,3.1,4.1]
195+--
186-- @
196-- @
187--
197--
188--
198--
@@ -201,10 +211,12 @@ enumerateFromFractional from = fromStreamD $ D.numFrom from
201-- example:
211-- example:
202--
212--
203-- @
213-- @
204−-- > S.toList $ S.take 4 $ S.enumerateFromThenFractional 1.1 2.1
214+-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenFractional 1.1 2.1
205-- [1.1,2.1,3.1,4.1]
215-- [1.1,2.1,3.1,4.1]
216+--
206−-- > S.toList $ S.take 4 $ S.enumerateFromThenFractional 1.1 (-2.1)
217+-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenFractional 1.1 (-2.1)
207-- [1.1,-2.1,-5.300000000000001,-8.500000000000002]
218-- [1.1,-2.1,-5.300000000000001,-8.500000000000002]
219+--
208-- @
220-- @
209--
221--
210-- @since 0.6.0
222-- @since 0.6.0
@@ -223,10 +235,12 @@ enumerateFromThenFractional from next = fromStreamD $ D.numFromThen from next
223-- example:
235-- example:
224--
236--
225-- @
237-- @
226−-- > S.toList $ S.enumerateFromToFractional 1.1 4
238+-- >>> Stream.toList $ Stream.enumerateFromToFractional 1.1 4
227-- [1.1,2.1,3.1,4.1]
239-- [1.1,2.1,3.1,4.1]
240+--
228−-- > S.toList $ S.enumerateFromToFractional 1.1 4.6
241+-- >>> Stream.toList $ Stream.enumerateFromToFractional 1.1 4.6
229-- [1.1,2.1,3.1,4.1,5.1]
242-- [1.1,2.1,3.1,4.1,5.1]
243+--
230-- @
244-- @
231--
245--
232-- Notice that the last element is equal to the specified @to@ value after
246-- Notice that the last element is equal to the specified @to@ value after
@@ -249,10 +263,12 @@ enumerateFromToFractional from to =
249-- example:
263-- example:
250--
264--
251-- @
265-- @
252−-- > S.toList $ S.enumerateFromThenToFractional 0.1 2 6
266+-- >>> Stream.toList $ Stream.enumerateFromThenToFractional 0.1 2 6
253-- [0.1,2.0,3.9,5.799999999999999]
267-- [0.1,2.0,3.9,5.799999999999999]
268+--
254−-- > S.toList $ S.enumerateFromThenToFractional 0.1 (-2) (-6)
269+-- >>> Stream.toList $ Stream.enumerateFromThenToFractional 0.1 (-2) (-6)
255-- [0.1,-2.0,-4.1000000000000005,-6.200000000000001]
270-- [0.1,-2.0,-4.1000000000000005,-6.200000000000001]
271+--
256-- @
272-- @
257--
273--
258--
274--
@@ -327,16 +343,18 @@ class Enum a => Enumerable a where
327 -- generating an infinite stream when the type is not 'Bounded'.
343 -- generating an infinite stream when the type is not 'Bounded'.
328 --
344 --
329 -- @
345 -- @
330− -- > S.toList $ S.take 4 $ S.enumerateFrom (0 :: Int)
346+ -- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFrom (0 :: Int)
331 -- [0,1,2,3]
347 -- [0,1,2,3]
348+ --
332 -- @
349 -- @
333 --
350 --
334 -- For 'Fractional' types, enumeration is numerically stable. However, no
351 -- For 'Fractional' types, enumeration is numerically stable. However, no
335 -- overflow or underflow checks are performed.
352 -- overflow or underflow checks are performed.
336 --
353 --
337 -- @
354 -- @
338− -- > S.toList $ S.take 4 $ S.enumerateFrom 1.1
355+ -- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFrom 1.1
339 -- [1.1,2.1,3.1,4.1]
356 -- [1.1,2.1,3.1,4.1]
357+ --
340 -- @
358 -- @
341 --
359 --
342 -- @since 0.6.0
360 -- @since 0.6.0
@@ -347,18 +365,21 @@ class Enum a => Enumerable a where
347 -- empty stream is returned.
365 -- empty stream is returned.
348 --
366 --
349 -- @
367 -- @
350− -- > S.toList $ S.enumerateFromTo 0 4
368+ -- >>> Stream.toList $ Stream.enumerateFromTo 0 4
351 -- [0,1,2,3,4]
369 -- [0,1,2,3,4]
370+ --
352 -- @
371 -- @
353 --
372 --
354 -- For 'Fractional' types, the last element is equal to the specified @to@
373 -- For 'Fractional' types, the last element is equal to the specified @to@
355 -- value after rounding to the nearest integral value.
374 -- value after rounding to the nearest integral value.
356 --
375 --
357 -- @
376 -- @
358− -- > S.toList $ S.enumerateFromTo 1.1 4
377+ -- >>> Stream.toList $ Stream.enumerateFromTo 1.1 4
359 -- [1.1,2.1,3.1,4.1]
378 -- [1.1,2.1,3.1,4.1]
379+ --
360− -- > S.toList $ S.enumerateFromTo 1.1 4.6
380+ -- >>> Stream.toList $ Stream.enumerateFromTo 1.1 4.6
361 -- [1.1,2.1,3.1,4.1,5.1]
381 -- [1.1,2.1,3.1,4.1,5.1]
382+ --
362 -- @
383 -- @
363 --
384 --
364 -- @since 0.6.0
385 -- @since 0.6.0
@@ -372,10 +393,12 @@ class Enum a => Enumerable a where
372 -- unbounded types it keeps enumerating infinitely.
393 -- unbounded types it keeps enumerating infinitely.
373 --
394 --
374 -- @
395 -- @
375− -- > S.toList $ S.take 4 $ S.enumerateFromThen 0 2
396+ -- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThen 0 2
376 -- [0,2,4,6]
397 -- [0,2,4,6]
398+ --
377− -- > S.toList $ S.take 4 $ S.enumerateFromThen 0 (-2)
399+ -- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThen 0 (-2)
378 -- [0,-2,-4,-6]
400 -- [0,-2,-4,-6]
401+ --
379 -- @
402 -- @
380 --
403 --
381 -- @since 0.6.0
404 -- @since 0.6.0
@@ -388,10 +411,12 @@ class Enum a => Enumerable a where
388 -- after @from@.
411 -- after @from@.
389 --
412 --
390 -- @
413 -- @
391− -- > S.toList $ S.enumerateFromThenTo 0 2 6
414+ -- >>> Stream.toList $ Stream.enumerateFromThenTo 0 2 6
392 -- [0,2,4,6]
415 -- [0,2,4,6]
416+ --
393− -- > S.toList $ S.enumerateFromThenTo 0 (-2) (-6)
417+ -- >>> Stream.toList $ Stream.enumerateFromThenTo 0 (-2) (-6)
394 -- [0,-2,-4,-6]
418 -- [0,-2,-4,-6]
419+ --
395 -- @
420 -- @
396 --
421 --
397 -- @since 0.6.0
422 -- @since 0.6.0
src/Streamly/Internal/Data/Stream/IsStream/Expand.hs+15−13
@@ -187,6 +187,7 @@ import Prelude hiding (concat, concatMap)
187
187
188-- $setup
188-- $setup
189-- >>> :m
189-- >>> :m
190+-- >>> import Data.IORef
190-- >>> import Prelude hiding (zipWith, concatMap, concat)
191-- >>> import Prelude hiding (zipWith, concatMap, concat)
191-- >>> import qualified Streamly.Prelude as Stream
192-- >>> import qualified Streamly.Prelude as Stream
192-- >>> import Streamly.Internal.Data.Stream.IsStream as Stream
193-- >>> import Streamly.Internal.Data.Stream.IsStream as Stream
@@ -237,6 +238,7 @@ append m1 m2 = fromStreamD $ D.append (toStreamD m1) (toStreamD m2)
237-- >>> import Data.Functor.Identity (Identity)
238-- >>> import Data.Functor.Identity (Identity)
238-- >>> Stream.interleave "ab" ",,,," :: Stream.SerialT Identity Char
239-- >>> Stream.interleave "ab" ",,,," :: Stream.SerialT Identity Char
239-- fromList "a,b,,,"
240-- fromList "a,b,,,"
241+--
240-- >>> Stream.interleave "abcd" ",," :: Stream.SerialT Identity Char
242-- >>> Stream.interleave "abcd" ",," :: Stream.SerialT Identity Char
241-- fromList "a,b,cd"
243-- fromList "a,b,cd"
242--
244--
@@ -369,27 +371,27 @@ mergeBy f m1 m2 = fromStreamS $ S.mergeBy f (toStreamS m1) (toStreamS m2)
369--
371--
370-- @
372-- @
371-- > randomly _ _ = randomIO >>= \x -> return $ if x then LT else GT
373-- > randomly _ _ = randomIO >>= \x -> return $ if x then LT else GT
372−-- > S.toList $ S.mergeByM randomly (S.fromList [1,1,1,1]) (S.fromList [2,2,2,2])
374+-- > Stream.toList $ Stream.mergeByM randomly (Stream.fromList [1,1,1,1]) (Stream.fromList [2,2,2,2])
373-- [2,1,2,2,2,1,1,1]
375-- [2,1,2,2,2,1,1,1]
374-- @
376-- @
375--
377--
376-- Merge two streams in a proportion of 2:1:
378-- Merge two streams in a proportion of 2:1:
377--
379--
378-- @
380-- @
381+-- >>> :{
382+-- do
379−-- proportionately m n = do
383+-- let proportionately m n = do
380−-- ref <- newIORef $ cycle $ concat [replicate m LT, replicate n GT]
384+-- ref <- newIORef $ cycle $ Prelude.concat [Prelude.replicate m LT, Prelude.replicate n GT]
381−-- return $ \\_ _ -> do
385+-- return $ \_ _ -> do
382−-- r <- readIORef ref
386+-- r <- readIORef ref
383−-- writeIORef ref $ tail r
387+-- writeIORef ref $ Prelude.tail r
384−-- return $ head r
388+-- return $ Prelude.head r
385−--
386−-- main = do
387-- f <- proportionately 2 1
389-- f <- proportionately 2 1
388−-- xs <- S.toList $ S.mergeByM f (S.fromList [1,1,1,1,1,1]) (S.fromList [2,2,2])
390+-- xs <- Stream.toList $ Stream.mergeByM f (Stream.fromList [1,1,1,1,1,1]) (Stream.fromList [2,2,2])
389-- print xs
391-- print xs
390−-- @
392+-- :}
391−-- @
392-- [1,1,2,1,1,2,1,1,2]
393-- [1,1,2,1,1,2,1,1,2]
394+--
393-- @
395-- @
394--
396--
395-- @since 0.6.0
397-- @since 0.6.0
@@ -420,7 +422,7 @@ mergeEndByFirst f m1 m2 = fromStreamS $
420-- | Same as @'mergeBy' 'compare'@.
422-- | Same as @'mergeBy' 'compare'@.
421--
423--
422-- @
424-- @
423−-- > S.toList $ S.merge (S.fromList [1,3,5]) (S.fromList [2,4,6,8])
425+-- >>> Stream.toList $ Stream.merge (Stream.fromList [1,3,5]) (Stream.fromList [2,4,6,8])
424-- [1,2,3,4,5,6,8]
426-- [1,2,3,4,5,6,8]
425-- @
427-- @
426--
428--
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+12−12
@@ -168,14 +168,15 @@ unfold0 unf = unfold unf (error "unfold0: unexpected void evaluation")
168-- For example,
168-- For example,
169--
169--
170-- @
170-- @
171+-- >>> :{
171-- let f b =
172-- let f b =
172-- if b > 3
173-- if b > 3
173-- then Nothing
174-- then Nothing
174-- else Just (b, b + 1)
175-- else Just (b, b + 1)
175−-- in toList $ unfoldr f 0
176+-- in Stream.toList $ Stream.unfoldr f 0
176−-- @
177+-- :}
177−-- @
178-- [0,1,2,3]
178-- [0,1,2,3]
179+--
179-- @
180-- @
180--
181--
181-- @since 0.1.0
182-- @since 0.1.0
@@ -191,17 +192,15 @@ unfoldr step seed = fromStreamS (S.unfoldr step seed)
191-- example,
192-- example,
192--
193--
193-- @
194-- @
195+-- >>> :{
194-- let f b =
196-- let f b =
195-- if b > 3
197-- if b > 3
196-- then return Nothing
198-- then return Nothing
197−-- else print b >> return (Just (b, b + 1))
199+-- else return (Just (b, b + 1))
198−-- in drain $ unfoldrM f 0
200+-- in Stream.toList $ Stream.unfoldrM f 0
199−-- @
201+-- :}
200−-- @
201−-- 0
202+-- [0,1,2,3]
202−-- 1
203+--
203−-- 2
204−-- 3
205-- @
204-- @
206-- When run concurrently, the next unfold step can run concurrently with the
205-- When run concurrently, the next unfold step can run concurrently with the
207-- processing of the output of the previous step. Note that more than one step
206-- processing of the output of the previous step. Note that more than one step
@@ -444,8 +443,9 @@ fromIndicesMSerial = fromStreamS . S.fromIndicesM
444-- element.
443-- element.
445--
444--
446-- @
445-- @
447−-- > S.toList $ S.take 5 $ S.iterate (+1) 1
446+-- >>> Stream.toList $ Stream.take 5 $ Stream.iterate (+1) 1
448-- [1,2,3,4,5]
447-- [1,2,3,4,5]
448+--
449-- @
449-- @
450--
450--
451-- @since 0.1.2
451-- @since 0.1.2
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+4−4
@@ -312,10 +312,10 @@ foldSequence _f _m = undefined
312-- the fold is used to generate the next fold and so on.
312-- the fold is used to generate the next fold and so on.
313--
313--
314-- @
314-- @
315−-- > import Data.Monoid (Sum(..))
315+-- >>> import Data.Monoid (Sum(..))
316−-- > f x = return (Fold.take 2 (Fold.sconcat x))
316+-- >>> f x = return (Fold.take 2 (Fold.sconcat x))
317−-- > s = Stream.map Sum $ Stream.fromList [1..10]
317+-- >>> s = Stream.map Sum $ Stream.fromList [1..10]
318−-- > Stream.toList $ Stream.map getSum $ Stream.foldIterateM f 0 s
318+-- >>> Stream.toList $ Stream.map getSum $ Stream.foldIterateM f 0 s
319-- [3,10,21,36,55,55]
319-- [3,10,21,36,55,55]
320--
320--
321-- @
321-- @
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+75−41
@@ -263,6 +263,9 @@ import Prelude hiding
263--
263--
264-- $setup
264-- $setup
265-- >>> :m
265-- >>> :m
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)
287
290
288-- | Right fold to a streaming monad.
291-- | Right fold to a streaming monad.
289--
292--
290−-- > foldrS S.cons S.nil === id
293+-- > foldrS Stream.cons Stream.nil === id
291--
294--
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.
347--
350--
348-- @
351-- @
349−-- > drain $ S.mapM putStr $ S.fromList ["a", "b", "c"]
352+-- >>> drain $ Stream.mapM putStr $ Stream.fromList ["a", "b", "c"]
350-- abc
353-- abc
351--
354--
355+-- >>> :{
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))
358+-- :}
359+-- 1
360+-- ...
361+-- 1
354--
362--
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))
357-- @
365-- @
358--
366--
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.
378--
386--
379-- @
387-- @
380−-- > drain $ S.sequence $ S.fromList [putStr "a", putStr "b", putStrLn "c"]
388+-- >>> drain $ Stream.sequence $ Stream.fromList [putStr "a", putStr "b", putStrLn "c"]
381-- abc
389-- abc
382--
390--
391+-- >>> :{
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)
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
385--
406--
386−-- drain $ S.replicateM 10 (return $ threadDelay 1000000 >> print 1)
387−-- & (fromAsync . S.sequence)
388-- @
407-- @
389--
408--
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 =
451-- @
470-- @
452--
471--
453-- @
472-- @
454−-- > S.drain $ S.tapAsync (S.mapM_ print) (S.enumerateFromTo 1 2)
473+-- >>> Stream.drain $ Stream.tapAsync (Fold.drainBy print) (Stream.enumerateFromTo 1 2)
455-- 1
474-- 1
456-- 2
475-- 2
476+--
457-- @
477-- @
458--
478--
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:
480--
500--
481-- @
501-- @
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
484-- @
504-- @
485--
505--
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 =
509--
529--
510-- @
530-- @
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"
534+-- [1.0,0.5,0.5]
514−-- 1 elements processed
535+-- "1 elements processed"
515-- @
536-- @
516--
537--
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.
531--
552--
532-- @
553-- @
533−-- > S.drain $ S.trace print (S.enumerateFromTo 1 2)
554+-- >>> Stream.drain $ Stream.trace print (Stream.enumerateFromTo 1 2)
534-- 1
555-- 1
535-- 2
556-- 2
557+--
536-- @
558-- @
537--
559--
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.
547--
569--
548-- @
570-- @
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"
574+--
552-- @
575-- @
553--
576--
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.
644--
667--
645-- @
668-- @
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]
671+--
648-- @
672-- @
649--
673--
650-- @
674-- @
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]]
677+--
653-- @
678-- @
654--
679--
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'@:
666--
691--
667-- @
692-- @
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)
695+--
670-- @
696-- @
671--
697--
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:
674--
700--
675-- @
701-- @
702+-- >>> :{
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]
706+-- :}
679-- (10,24)
707-- (10,24)
708+--
680-- @
709-- @
681--
710--
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
692
721
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.
694--
723--
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
696--
725--
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.
731--
760--
732-- @
761-- @
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]
764+--
735-- @
765-- @
736--
766--
737-- @since 0.6.0
767-- @since 0.6.0
@@ -821,8 +851,9 @@ uniq = fromStreamD . D.uniq . toStreamD
821-- @
851-- @
822--
852--
823-- @
853-- @
824−-- > Stream.pruneBy isSpace (Stream.fromList " hello world! ")
854+-- > Stream.prune isSpace (Stream.fromList " hello world! ")
825-- "hello world!"
855-- "hello world!"
856+--
826-- @
857-- @
827--
858--
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.
881--
912--
882-- @
913-- @
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]
916+--
885-- @
917-- @
886--
918--
887-- @since 0.6.0
919-- @since 0.6.0
@@ -1096,8 +1128,9 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
1096-- @
1128-- @
1097--
1129--
1098-- @
1130-- @
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]
1133+--
1101-- @
1134-- @
1102--
1135--
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.
1132--
1165--
1133-- @
1166-- @
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"
1169+--
1136-- @
1170-- @
1137--
1171--
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.
1155--
1189--
1156-- @
1190-- @
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+--
1158-- @
1194-- @
1159--
1195--
1160-- /Pre-release/
1196-- /Pre-release/
@@ -1270,8 +1306,8 @@ reassembleBy = undefined
1270------------------------------------------------------------------------------
1306------------------------------------------------------------------------------
1271
1307
1272-- |
1308-- |
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)
1275--
1311--
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.
1277--
1313--
@@ -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
1285
1321
1286-- |
1322-- |
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))
1289--
1325--
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:
1309--
1345--
1310−-- S.mapM_ print $ S.timestamped $ S.delay $ S.enumerateFromTo 1 3
1346+-- Stream.mapM_ print $ Stream.timestamped $ Stream.delay $ Stream.enumerateFromTo 1 3
1311--
1347--
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:
1417--
1453--
1418-- @
1454-- @
1419−-- mapMaybe f = S.map 'fromJust' . S.filter 'isJust' . S.map f
1455+-- mapMaybe f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.map f
1420-- @
1456-- @
1421--
1457--
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:
1430--
1466--
1431-- @
1467-- @
1432−-- mapMaybeM f = S.map 'fromJust' . S.filter 'isJust' . S.mapM f
1468+-- mapMaybeM f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.mapM f
1433-- @
1469-- @
1434--
1470--
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.
1490--
1526--
1491--
1527--
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)
src/Streamly/Prelude.hs+8−6
@@ -1126,8 +1126,9 @@ import Streamly.Internal.Data.Stream.IsStream
1126-- works. For example:
1126-- works. For example:
1127--
1127--
1128-- @
1128-- @
1129−-- > S.foldl' (+) 0 $ S.fromList [1,2,3,4]
1129+-- >>> Stream.foldl' (+) 0 $ Stream.fromList [1,2,3,4]
1130-- 10
1130-- 10
1131+--
1131-- @
1132-- @
1132--
1133--
1133-- @
1134-- @
@@ -1150,8 +1151,9 @@ import Streamly.Internal.Data.Stream.IsStream
1150-- reverse (LIFO) order:
1151-- reverse (LIFO) order:
1151--
1152--
1152-- @
1153-- @
1153−-- > S.foldl' (flip (:)) [] $ S.fromList [1,2,3,4]
1154+-- >>> Stream.foldl' (flip (:)) [] $ Stream.fromList [1,2,3,4]
1154-- [4,3,2,1]
1155-- [4,3,2,1]
1156+--
1155-- @
1157-- @
1156--
1158--
1157-- A left fold is a push fold. The producer pushes its contents to the step
1159-- A left fold is a push fold. The producer pushes its contents to the step
@@ -1200,8 +1202,8 @@ import Streamly.Internal.Data.Stream.IsStream
1200--
1202--
1201-- @
1203-- @
1202-- ...
1204-- ...
1203−-- $ S.maxBuffer 10
1205+-- $ Stream.maxBuffer 10
1204−-- $ S.mapM ...
1206+-- $ Stream.mapM ...
1205-- ...
1207-- ...
1206-- @
1208-- @
1207--
1209--
@@ -1211,8 +1213,8 @@ import Streamly.Internal.Data.Stream.IsStream
1211--
1213--
1212-- @
1214-- @
1213-- ...
1215-- ...
1214−-- & S.maxBuffer 10
1216+-- & Stream.maxBuffer 10
1215−-- & S.mapM ...
1217+-- & Stream.mapM ...
1216-- ...
1218-- ...
1217-- @
1219-- @
1218
1220