Use full module names in documentation

This commit is contained in:
Ranjeet Kumar Ranjan 2021-05-30 21:19:54 +05:30 committed by Harendra Kumar
parent 4ca4d31fec
commit f95cb897e1
6 changed files with 163 additions and 100 deletions

View File

@ -78,10 +78,13 @@ import qualified Streamly.Internal.Data.Stream.Serial as Serial (map)
-- check for overflow, underflow or bounds.
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFromStepIntegral 0 2
-- >>> import Streamly.Internal.Data.Stream.IsStream.Enumeration as Stream
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromStepIntegral 0 2
-- [0,2,4,6]
-- > S.toList $ S.take 3 $ S.enumerateFromStepIntegral 0 (-2)
--
-- >>> Stream.toList $ Stream.take 3 $ Stream.enumerateFromStepIntegral 0 (-2)
-- [0,-2,-4]
--
-- @
--
-- @since 0.6.0
@ -97,8 +100,9 @@ enumerateFromStepIntegral from stride =
-- increments of @1@. The stream is bounded by the size of the 'Integral' type.
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFromIntegral (0 :: Int)
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromIntegral (0 :: Int)
-- [0,1,2,3]
--
-- @
--
-- @since 0.6.0
@ -114,10 +118,12 @@ enumerateFromIntegral from = fromStreamD $ D.enumerateFromIntegral from
-- The stream is bounded by the size of the 'Integral' type.
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFromThenIntegral (0 :: Int) 2
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenIntegral (0 :: Int) 2
-- [0,2,4,6]
-- > S.toList $ S.take 4 $ S.enumerateFromThenIntegral (0 :: Int) (-2)
--
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenIntegral (0 :: Int) (-2)
-- [0,-2,-4,-6]
--
-- @
--
-- @since 0.6.0
@ -134,8 +140,9 @@ enumerateFromThenIntegral from next =
-- @to@.
--
-- @
-- > S.toList $ S.enumerateFromToIntegral 0 4
-- >>> Stream.toList $ Stream.enumerateFromToIntegral 0 4
-- [0,1,2,3,4]
--
-- @
--
-- @since 0.6.0
@ -150,10 +157,12 @@ enumerateFromToIntegral from to =
-- elements are in increments of @then - from@ up to @to@.
--
-- @
-- > S.toList $ S.enumerateFromThenToIntegral 0 2 6
-- >>> Stream.toList $ Stream.enumerateFromThenToIntegral 0 2 6
-- [0,2,4,6]
-- > S.toList $ S.enumerateFromThenToIntegral 0 (-2) (-6)
--
-- >>> Stream.toList $ Stream.enumerateFromThenToIntegral 0 (-2) (-6)
-- [0,-2,-4,-6]
--
-- @
--
-- @since 0.6.0
@ -181,8 +190,9 @@ enumerateFromThenToIntegral from next to =
-- This is the equivalent to 'enumFrom' for 'Fractional' types. For example:
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFromFractional 1.1
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromFractional 1.1
-- [1.1,2.1,3.1,4.1]
--
-- @
--
--
@ -201,10 +211,12 @@ enumerateFromFractional from = fromStreamD $ D.numFrom from
-- example:
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFromThenFractional 1.1 2.1
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenFractional 1.1 2.1
-- [1.1,2.1,3.1,4.1]
-- > S.toList $ S.take 4 $ S.enumerateFromThenFractional 1.1 (-2.1)
--
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThenFractional 1.1 (-2.1)
-- [1.1,-2.1,-5.300000000000001,-8.500000000000002]
--
-- @
--
-- @since 0.6.0
@ -223,10 +235,12 @@ enumerateFromThenFractional from next = fromStreamD $ D.numFromThen from next
-- example:
--
-- @
-- > S.toList $ S.enumerateFromToFractional 1.1 4
-- >>> Stream.toList $ Stream.enumerateFromToFractional 1.1 4
-- [1.1,2.1,3.1,4.1]
-- > S.toList $ S.enumerateFromToFractional 1.1 4.6
--
-- >>> Stream.toList $ Stream.enumerateFromToFractional 1.1 4.6
-- [1.1,2.1,3.1,4.1,5.1]
--
-- @
--
-- Notice that the last element is equal to the specified @to@ value after
@ -249,10 +263,12 @@ enumerateFromToFractional from to =
-- example:
--
-- @
-- > S.toList $ S.enumerateFromThenToFractional 0.1 2 6
-- >>> Stream.toList $ Stream.enumerateFromThenToFractional 0.1 2 6
-- [0.1,2.0,3.9,5.799999999999999]
-- > S.toList $ S.enumerateFromThenToFractional 0.1 (-2) (-6)
--
-- >>> Stream.toList $ Stream.enumerateFromThenToFractional 0.1 (-2) (-6)
-- [0.1,-2.0,-4.1000000000000005,-6.200000000000001]
--
-- @
--
--
@ -327,16 +343,18 @@ class Enum a => Enumerable a where
-- generating an infinite stream when the type is not 'Bounded'.
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFrom (0 :: Int)
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFrom (0 :: Int)
-- [0,1,2,3]
--
-- @
--
-- For 'Fractional' types, enumeration is numerically stable. However, no
-- overflow or underflow checks are performed.
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFrom 1.1
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFrom 1.1
-- [1.1,2.1,3.1,4.1]
--
-- @
--
-- @since 0.6.0
@ -347,18 +365,21 @@ class Enum a => Enumerable a where
-- empty stream is returned.
--
-- @
-- > S.toList $ S.enumerateFromTo 0 4
-- >>> Stream.toList $ Stream.enumerateFromTo 0 4
-- [0,1,2,3,4]
--
-- @
--
-- For 'Fractional' types, the last element is equal to the specified @to@
-- value after rounding to the nearest integral value.
--
-- @
-- > S.toList $ S.enumerateFromTo 1.1 4
-- >>> Stream.toList $ Stream.enumerateFromTo 1.1 4
-- [1.1,2.1,3.1,4.1]
-- > S.toList $ S.enumerateFromTo 1.1 4.6
--
-- >>> Stream.toList $ Stream.enumerateFromTo 1.1 4.6
-- [1.1,2.1,3.1,4.1,5.1]
--
-- @
--
-- @since 0.6.0
@ -372,10 +393,12 @@ class Enum a => Enumerable a where
-- unbounded types it keeps enumerating infinitely.
--
-- @
-- > S.toList $ S.take 4 $ S.enumerateFromThen 0 2
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThen 0 2
-- [0,2,4,6]
-- > S.toList $ S.take 4 $ S.enumerateFromThen 0 (-2)
--
-- >>> Stream.toList $ Stream.take 4 $ Stream.enumerateFromThen 0 (-2)
-- [0,-2,-4,-6]
--
-- @
--
-- @since 0.6.0
@ -388,10 +411,12 @@ class Enum a => Enumerable a where
-- after @from@.
--
-- @
-- > S.toList $ S.enumerateFromThenTo 0 2 6
-- >>> Stream.toList $ Stream.enumerateFromThenTo 0 2 6
-- [0,2,4,6]
-- > S.toList $ S.enumerateFromThenTo 0 (-2) (-6)
--
-- >>> Stream.toList $ Stream.enumerateFromThenTo 0 (-2) (-6)
-- [0,-2,-4,-6]
--
-- @
--
-- @since 0.6.0

View File

@ -187,6 +187,7 @@ import Prelude hiding (concat, concatMap)
-- $setup
-- >>> :m
-- >>> import Data.IORef
-- >>> import Prelude hiding (zipWith, concatMap, concat)
-- >>> import qualified Streamly.Prelude as Stream
-- >>> import Streamly.Internal.Data.Stream.IsStream as Stream
@ -237,6 +238,7 @@ append m1 m2 = fromStreamD $ D.append (toStreamD m1) (toStreamD m2)
-- >>> import Data.Functor.Identity (Identity)
-- >>> Stream.interleave "ab" ",,,," :: Stream.SerialT Identity Char
-- fromList "a,b,,,"
--
-- >>> Stream.interleave "abcd" ",," :: Stream.SerialT Identity Char
-- fromList "a,b,cd"
--
@ -369,27 +371,27 @@ mergeBy f m1 m2 = fromStreamS $ S.mergeBy f (toStreamS m1) (toStreamS m2)
--
-- @
-- > randomly _ _ = randomIO >>= \x -> return $ if x then LT else GT
-- > S.toList $ S.mergeByM randomly (S.fromList [1,1,1,1]) (S.fromList [2,2,2,2])
-- > Stream.toList $ Stream.mergeByM randomly (Stream.fromList [1,1,1,1]) (Stream.fromList [2,2,2,2])
-- [2,1,2,2,2,1,1,1]
-- @
--
-- Merge two streams in a proportion of 2:1:
--
-- @
-- proportionately m n = do
-- ref <- newIORef $ cycle $ concat [replicate m LT, replicate n GT]
-- return $ \\_ _ -> do
-- r <- readIORef ref
-- writeIORef ref $ tail r
-- return $ head r
--
-- main = do
-- >>> :{
-- do
-- let proportionately m n = do
-- ref <- newIORef $ cycle $ Prelude.concat [Prelude.replicate m LT, Prelude.replicate n GT]
-- return $ \_ _ -> do
-- r <- readIORef ref
-- writeIORef ref $ Prelude.tail r
-- return $ Prelude.head r
-- f <- proportionately 2 1
-- xs <- S.toList $ S.mergeByM f (S.fromList [1,1,1,1,1,1]) (S.fromList [2,2,2])
-- xs <- Stream.toList $ Stream.mergeByM f (Stream.fromList [1,1,1,1,1,1]) (Stream.fromList [2,2,2])
-- print xs
-- @
-- @
-- :}
-- [1,1,2,1,1,2,1,1,2]
--
-- @
--
-- @since 0.6.0
@ -420,7 +422,7 @@ mergeEndByFirst f m1 m2 = fromStreamS $
-- | Same as @'mergeBy' 'compare'@.
--
-- @
-- > S.toList $ S.merge (S.fromList [1,3,5]) (S.fromList [2,4,6,8])
-- >>> Stream.toList $ Stream.merge (Stream.fromList [1,3,5]) (Stream.fromList [2,4,6,8])
-- [1,2,3,4,5,6,8]
-- @
--

View File

@ -168,14 +168,15 @@ unfold0 unf = unfold unf (error "unfold0: unexpected void evaluation")
-- For example,
--
-- @
-- >>> :{
-- let f b =
-- if b > 3
-- then Nothing
-- else Just (b, b + 1)
-- in toList $ unfoldr f 0
-- @
-- @
-- in Stream.toList $ Stream.unfoldr f 0
-- :}
-- [0,1,2,3]
--
-- @
--
-- @since 0.1.0
@ -191,17 +192,15 @@ unfoldr step seed = fromStreamS (S.unfoldr step seed)
-- example,
--
-- @
-- >>> :{
-- let f b =
-- if b > 3
-- then return Nothing
-- else print b >> return (Just (b, b + 1))
-- in drain $ unfoldrM f 0
-- @
-- @
-- 0
-- 1
-- 2
-- 3
-- else return (Just (b, b + 1))
-- in Stream.toList $ Stream.unfoldrM f 0
-- :}
-- [0,1,2,3]
--
-- @
-- When run concurrently, the next unfold step can run concurrently with the
-- processing of the output of the previous step. Note that more than one step
@ -444,8 +443,9 @@ fromIndicesMSerial = fromStreamS . S.fromIndicesM
-- element.
--
-- @
-- > S.toList $ S.take 5 $ S.iterate (+1) 1
-- >>> Stream.toList $ Stream.take 5 $ Stream.iterate (+1) 1
-- [1,2,3,4,5]
--
-- @
--
-- @since 0.1.2

View File

@ -312,10 +312,10 @@ foldSequence _f _m = undefined
-- the fold is used to generate the next fold and so on.
--
-- @
-- > import Data.Monoid (Sum(..))
-- > f x = return (Fold.take 2 (Fold.sconcat x))
-- > s = Stream.map Sum $ Stream.fromList [1..10]
-- > Stream.toList $ Stream.map getSum $ Stream.foldIterateM f 0 s
-- >>> import Data.Monoid (Sum(..))
-- >>> f x = return (Fold.take 2 (Fold.sconcat x))
-- >>> s = Stream.map Sum $ Stream.fromList [1..10]
-- >>> Stream.toList $ Stream.map getSum $ Stream.foldIterateM f 0 s
-- [3,10,21,36,55,55]
--
-- @

View File

@ -263,6 +263,9 @@ import Prelude hiding
--
-- $setup
-- >>> :m
-- >>> import Control.Concurrent (threadDelay)
-- >>> import Data.Function ((&))
-- >>> import Streamly.Prelude ((|$))
-- >>> import Prelude hiding ( filter, drop, dropWhile, take, takeWhile, foldr, map, mapM, sequence, reverse, foldr1 , scanl, scanl1)
-- >>> import qualified Streamly.Prelude as Stream
-- >>> import Streamly.Internal.Data.Stream.IsStream as Stream
@ -287,7 +290,7 @@ transform pipe xs = fromStreamD $ D.transform pipe (toStreamD xs)
-- | Right fold to a streaming monad.
--
-- > foldrS S.cons S.nil === id
-- > foldrS Stream.cons Stream.nil === id
--
-- 'foldrS' can be used to perform stateless stream to stream transformations
-- 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)
-- the output of the resulting action.
--
-- @
-- > drain $ S.mapM putStr $ S.fromList ["a", "b", "c"]
-- >>> drain $ Stream.mapM putStr $ Stream.fromList ["a", "b", "c"]
-- abc
--
-- drain $ S.replicateM 10 (return 1)
-- & (fromSerial . S.mapM (\\x -> threadDelay 1000000 >> print x))
-- >>> :{
-- drain $ Stream.replicateM 10 (return 1)
-- & (fromSerial . Stream.mapM (\x -> threadDelay 1000000 >> print x))
-- :}
-- 1
-- ...
-- 1
--
-- drain $ S.replicateM 10 (return 1)
-- & (fromAsync . S.mapM (\\x -> threadDelay 1000000 >> print x))
-- > drain $ Stream.replicateM 10 (return 1)
-- & (fromAsync . Stream.mapM (\x -> threadDelay 1000000 >> print x))
-- @
--
-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@ -377,14 +385,25 @@ mapMSerial = Serial.mapM
-- those actions.
--
-- @
-- > drain $ S.sequence $ S.fromList [putStr "a", putStr "b", putStrLn "c"]
-- >>> drain $ Stream.sequence $ Stream.fromList [putStr "a", putStr "b", putStrLn "c"]
-- abc
--
-- drain $ S.replicateM 10 (return $ threadDelay 1000000 >> print 1)
-- & (fromSerial . S.sequence)
-- >>> :{
-- drain $ Stream.replicateM 10 (return $ threadDelay 1000000 >> print 1)
-- & (fromSerial . Stream.sequence)
-- :}
-- 1
-- ...
-- 1
--
-- >>> :{
-- drain $ Stream.replicateM 10 (return $ threadDelay 1000000 >> print 1)
-- & (fromAsync . Stream.sequence)
-- :}
-- 1
-- ...
-- 1
--
-- drain $ S.replicateM 10 (return $ threadDelay 1000000 >> print 1)
-- & (fromAsync . S.sequence)
-- @
--
-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@ -451,9 +470,10 @@ tapOffsetEvery offset n f xs =
-- @
--
-- @
-- > S.drain $ S.tapAsync (S.mapM_ print) (S.enumerateFromTo 1 2)
-- >>> Stream.drain $ Stream.tapAsync (Fold.drainBy print) (Stream.enumerateFromTo 1 2)
-- 1
-- 2
--
-- @
--
-- 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)
-- For example, to print the count of elements processed every second:
--
-- @
-- > S.drain $ S.pollCounts (const True) (S.rollingMap (-) . S.delayPost 1) (FL.drainBy print)
-- $ S.enumerateFrom 0
-- > Stream.drain $ Stream.pollCounts (const True) (Stream.rollingMap (-) . Stream.delayPost 1) (FLold.drainBy print)
-- $ Stream.enumerateFrom 0
-- @
--
-- Note: This may not work correctly on 32-bit machines.
@ -509,9 +529,10 @@ pollCounts predicate transf f xs =
--
-- @
-- > delay n = threadDelay (round $ n * 1000000) >> return n
-- > S.drain $ S.tapRate 2 (\\n -> print $ show n ++ " elements processed") (delay 1 S.|: delay 0.5 S.|: delay 0.5 S.|: S.nil)
-- 2 elements processed
-- 1 elements processed
-- > Stream.toList $ Stream.tapRate 2 (\n -> print $ show n ++ " elements processed") (delay 1 Stream.|: delay 0.5 Stream.|: delay 0.5 Stream.|: Stream.nil)
-- "2 elements processed"
-- [1.0,0.5,0.5]
-- "1 elements processed"
-- @
--
-- 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
-- discard the results.
--
-- @
-- > S.drain $ S.trace print (S.enumerateFromTo 1 2)
-- >>> Stream.drain $ Stream.trace print (Stream.enumerateFromTo 1 2)
-- 1
-- 2
--
-- @
--
-- Compare with 'tap'.
@ -546,9 +568,10 @@ trace f = mapM (\x -> void (f x) >> return x)
-- discard the results.
--
-- @
-- > S.drain $ S.trace_ (print "got here") (S.enumerateFromTo 1 2)
-- >>> Stream.drain $ Stream.trace_ (print "got here") (Stream.enumerateFromTo 1 2)
-- "got here"
-- "got here"
--
-- @
--
-- Same as 'interspersePrefix_' but always serial.
@ -643,13 +666,15 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
-- however it adds an extra element.
--
-- @
-- > S.toList $ S.scanl' (+) 0 $ fromList [1,2,3,4]
-- >>> Stream.toList $ Stream.scanl' (+) 0 $ fromList [1,2,3,4]
-- [0,1,3,6,10]
--
-- @
--
-- @
-- > S.toList $ S.scanl' (flip (:)) [] $ S.fromList [1,2,3,4]
-- >>> Stream.toList $ Stream.scanl' (flip (:)) [] $ Stream.fromList [1,2,3,4]
-- [[],[1],[2,1],[3,2,1],[4,3,2,1]]
--
-- @
--
-- 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
-- of the elements in a stream in one go using a @foldl'@:
--
-- @
-- > S.foldl' (\\(s, p) x -> (s + x, p * x)) (0,1) $ S.fromList \[1,2,3,4]
-- >>> Stream.foldl' (\(s, p) x -> (s + x, p * x)) (0,1) $ Stream.fromList [1,2,3,4]
-- (10,24)
--
-- @
--
-- Using @scanl'@ we can make it modular by computing the sum in the first
-- stage and passing it down to the next stage for computing the product:
--
-- @
-- > S.foldl' (\\(_, p) (s, x) -> (s, p * x)) (0,1)
-- $ S.scanl' (\\(s, _) x -> (s + x, x)) (0,1)
-- $ S.fromList \[1,2,3,4]
-- >>> :{
-- Stream.foldl' (\(_, p) (s, x) -> (s, p * x)) (0,1)
-- $ Stream.scanl' (\(s, _) x -> (s + x, x)) (0,1)
-- $ Stream.fromList [1,2,3,4]
-- :}
-- (10,24)
--
-- @
--
-- 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
-- | Like 'scanl'' but does not stream the initial value of the accumulator.
--
-- > postscanl' f z xs = S.drop 1 $ S.scanl' f z xs
-- > postscanl' f z xs = Stream.drop 1 $ Stream.scanl' f z xs
--
-- @since 0.7.0
{-# INLINE postscanl' #-}
@ -730,8 +759,9 @@ scanl1M' step m = fromStreamD $ D.scanl1M' step $ toStreamD m
-- is empty.
--
-- @
-- > S.toList $ S.scanl1 (+) $ fromList [1,2,3,4]
-- >>> Stream.toList $ Stream.scanl1' (+) $ fromList [1,2,3,4]
-- [1,3,6,10]
--
-- @
--
-- @since 0.6.0
@ -821,8 +851,9 @@ uniq = fromStreamD . D.uniq . toStreamD
-- @
--
-- @
-- > Stream.pruneBy isSpace (Stream.fromList " hello world! ")
-- > Stream.prune isSpace (Stream.fromList " hello world! ")
-- "hello world!"
--
-- @
--
-- Space: @O(1)@
@ -880,8 +911,9 @@ nubWindowBy = undefined -- fromStreamD . D.nubWithinBy . toStreamD
-- the given equality predicate.
--
-- @
-- > S.toList $ S.deleteBy (==) 3 $ S.fromList [1,3,3,5]
-- >>> Stream.toList $ Stream.deleteBy (==) 3 $ Stream.fromList [1,3,3,5]
-- [1,3,5]
--
-- @
--
-- @since 0.6.0
@ -1096,8 +1128,9 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
-- @
--
-- @
-- > S.toList $ S.insertBy compare 2 $ S.fromList [1,3,5]
-- >>> Stream.toList $ Stream.insertBy compare 2 $ Stream.fromList [1,3,5]
-- [1,2,3,5]
--
-- @
--
-- @since 0.6.0
@ -1131,8 +1164,9 @@ intersperseM_ m = fromStreamD . D.intersperseM_ m . toStreamD
-- elements.
--
-- @
-- > S.toList $ S.intersperseBySpan 2 (return ',') $ S.fromList "hello"
-- > Stream.toList $ Stream.intersperseBySpan 2 (return ',') $ Stream.fromList "hello"
-- "he,ll,o"
--
-- @
--
-- /Unimplemented/
@ -1154,7 +1188,9 @@ intersperseSuffix m = fromStreamD . D.intersperseSuffix m . toStreamD
-- | Insert a side effect after consuming an element of a stream.
--
-- @
-- > S.mapM_ putChar $ S.intersperseSuffix_ (threadDelay 1000000) $ S.fromList "hello"
-- >>> Stream.mapM_ putChar $ Stream.intersperseSuffix_ (threadDelay 1000000) $ Stream.fromList "hello"
-- hello
--
-- @
--
-- /Pre-release/
@ -1270,8 +1306,8 @@ reassembleBy = undefined
------------------------------------------------------------------------------
-- |
-- > indexed = S.postscanl' (\(i, _) x -> (i + 1, x)) (-1,undefined)
-- > indexed = S.zipWith (,) (S.enumerateFrom 0)
-- > indexed = Stream.postscanl' (\(i, _) x -> (i + 1, x)) (-1,undefined)
-- > indexed = Stream.zipWith (,) (Stream.enumerateFrom 0)
--
-- 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)
indexed = fromStreamD . D.indexed . toStreamD
-- |
-- > indexedR n = S.postscanl' (\(i, _) x -> (i - 1, x)) (n + 1,undefined)
-- > indexedR n = S.zipWith (,) (S.enumerateFromThen n (n - 1))
-- > indexedR n = Stream.postscanl' (\(i, _) x -> (i - 1, x)) (n + 1,undefined)
-- > indexedR n = Stream.zipWith (,) (Stream.enumerateFromThen n (n - 1))
--
-- Pair each element in a stream with its index, starting from the
-- given index @n@ and counting down.
@ -1307,7 +1343,7 @@ indexedR n = fromStreamD . D.indexedR n . toStreamD
-- If we do not do that then the following example will generate the same
-- timestamp for first two elements:
--
-- S.mapM_ print $ S.timestamped $ S.delay $ S.enumerateFromTo 1 3
-- Stream.mapM_ print $ Stream.timestamped $ Stream.delay $ Stream.enumerateFromTo 1 3
--
-- | Pair each element in a stream with an absolute timestamp, using a clock of
-- specified granularity. The timestamp is generated just before the element
@ -1416,7 +1452,7 @@ rollingMapM f m = fromStreamD $ D.rollingMapM f $ toStreamD m
-- Equivalent to:
--
-- @
-- mapMaybe f = S.map 'fromJust' . S.filter 'isJust' . S.map f
-- mapMaybe f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.map f
-- @
--
-- @since 0.3.0
@ -1429,7 +1465,7 @@ mapMaybe f m = fromStreamS $ S.mapMaybe f $ toStreamS m
-- Equivalent to:
--
-- @
-- mapMaybeM f = S.map 'fromJust' . S.filter 'isJust' . S.mapM f
-- mapMaybeM f = Stream.map 'fromJust' . Stream.filter 'isJust' . Stream.mapM f
-- @
--
-- /Concurrent (do not use with 'fromParallel' on infinite streams)/
@ -1489,8 +1525,6 @@ rights = fmap (fromRight undefined) . filter isRight
-- 1 second delay.
--
--
-- >>> import Control.Concurrent (threadDelay)
-- >>> import Streamly.Prelude ((|$))
-- >>> :{
-- Stream.drain $
-- Stream.mapM (\x -> threadDelay 1000000 >> print x)

View File

@ -1126,8 +1126,9 @@ import Streamly.Internal.Data.Stream.IsStream
-- works. For example:
--
-- @
-- > S.foldl' (+) 0 $ S.fromList [1,2,3,4]
-- >>> Stream.foldl' (+) 0 $ Stream.fromList [1,2,3,4]
-- 10
--
-- @
--
-- @
@ -1150,8 +1151,9 @@ import Streamly.Internal.Data.Stream.IsStream
-- reverse (LIFO) order:
--
-- @
-- > S.foldl' (flip (:)) [] $ S.fromList [1,2,3,4]
-- >>> Stream.foldl' (flip (:)) [] $ Stream.fromList [1,2,3,4]
-- [4,3,2,1]
--
-- @
--
-- 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
--
-- @
-- ...
-- $ S.maxBuffer 10
-- $ S.mapM ...
-- $ Stream.maxBuffer 10
-- $ Stream.mapM ...
-- ...
-- @
--
@ -1211,8 +1213,8 @@ import Streamly.Internal.Data.Stream.IsStream
--
-- @
-- ...
-- & S.maxBuffer 10
-- & S.mapM ...
-- & Stream.maxBuffer 10
-- & Stream.mapM ...
-- ...
-- @