on master help sign in
Move definitions under doctest
81a3c94Harendra Kumar
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+23−21
@@ -82,6 +82,11 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
82--
82--
83-- $setup
83-- $setup
84-- >>> :m
84-- >>> :m
85+-- >>> import Control.Concurrent (threadDelay)
86+-- >>> import Control.Monad (join)
87+-- >>> import Control.Monad.Trans.Class (lift)
88+-- >>> import Data.Function (fix, (&))
89+-- >>> import Data.Semigroup (cycle1)
85-- >>> import Prelude hiding (take, takeWhile, drop, reverse)
90-- >>> import Prelude hiding (take, takeWhile, drop, reverse)
86-- >>> import System.IO.Unsafe (unsafePerformIO)
91-- >>> import System.IO.Unsafe (unsafePerformIO)
87-- >>> import qualified Streamly.Prelude as Stream
92-- >>> import qualified Streamly.Prelude as Stream
@@ -156,17 +161,18 @@ fromEffect = K.fromEffect
156yieldM :: (Monad m, IsStream t) => m a -> t m a
161yieldM :: (Monad m, IsStream t) => m a -> t m a
157yieldM = fromEffect
162yieldM = fromEffect
158-- |
163-- |
159−-- @
160−-- repeatM = fix . consM
164+-- >>> repeatM = fix . consM
161−-- repeatM = cycle1 . fromEffect
165+-- >>> repeatM = cycle1 . fromEffect
162−-- @
163--
166--
164-- Generate a stream by repeatedly executing a monadic action forever.
167-- Generate a stream by repeatedly executing a monadic action forever.
165--
168--
166−-- @
169+-- >>> :{
170+-- repeatAsync =
167−-- drain $ fromSerial $ S.take 10 $ S.repeatM $ (threadDelay 1000000 >> print 1)
171+-- Stream.repeatM (threadDelay 1000000 >> print 1)
168−-- drain $ fromAsync $ S.take 10 $ S.repeatM $ (threadDelay 1000000 >> print 1)
172+-- & Stream.take 10
173+-- & Stream.fromAsync
174+-- & Stream.drain
169−-- @
175+-- :}
170--
176--
171-- /Concurrent, infinite (do not use with 'fromParallel')/
177-- /Concurrent, infinite (do not use with 'fromParallel')/
172--
178--
@@ -444,11 +450,11 @@ interjectSuffix n f xs = xs `Par.parallelFst` repeatM timed
444-- /Note:/ 'reverse'' is much faster than this, use that when performance
450-- /Note:/ 'reverse'' is much faster than this, use that when performance
445-- matters.
451-- matters.
446--
452--
447−-- > reverse = S.foldlT (flip S.cons) S.nil
448−--
449-- | Returns the elements of the stream in reverse order. The stream must be
453-- | Returns the elements of the stream in reverse order. The stream must be
450-- finite. Note that this necessarily buffers the entire stream in memory.
454-- finite. Note that this necessarily buffers the entire stream in memory.
451--
455--
456+-- >>> reverse = Stream.foldlT (flip Stream.cons) Stream.nil
457+--
452-- /Since 0.7.0 (Monad m constraint)/
458-- /Since 0.7.0 (Monad m constraint)/
453--
459--
454-- /Since: 0.1.1/
460-- /Since: 0.1.1/
@@ -480,12 +486,10 @@ concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
480-- | Map a stream producing function on each element of the stream and then
486-- | Map a stream producing function on each element of the stream and then
481-- flatten the results into a single stream.
487-- flatten the results into a single stream.
482--
488--
483−-- @
484−-- concatMap f = 'concatMapM' (return . f)
489+-- >>> concatMap f = Stream.concatMapM (return . f)
485−-- concatMap = 'concatMapWith' 'Serial.serial'
490+-- >>> concatMap f = Stream.concatMapWith Stream.serial f
486−-- concatMap f = 'concat . map f'
491+-- >>> concatMap f = Stream.concat . Stream.map f
487−-- concatMap f = 'unfoldMany' (UF.lmap f UF.fromStream)
492+-- >>> concatMap f = Stream.unfoldMany (Unfold.lmap f Unfold.fromStream)
488−-- @
489--
493--
490-- @since 0.6.0
494-- @since 0.6.0
491{-# INLINE concatMap #-}
495{-# INLINE concatMap #-}
@@ -495,11 +499,9 @@ concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
495-- | Given a stream value in the underlying monad, lift and join the underlying
499-- | Given a stream value in the underlying monad, lift and join the underlying
496-- monad with the stream monad.
500-- monad with the stream monad.
497--
501--
498−-- @
499−-- concatM = concat . fromEffect
502+-- >>> concatM = Stream.concat . Stream.fromEffect
500−-- concatM = concat . lift -- requires @(MonadTrans t)@
503+-- >>> concatM = Stream.concat . lift -- requires (MonadTrans t)
501−-- concatM = join . lift -- requires @(MonadTrans t@, @Monad (t m))@
504+-- >>> concatM = join . lift -- requires (MonadTrans t, Monad (t m))
502−-- @
503--
505--
504-- See also: 'concat', 'sequence'
506-- See also: 'concat', 'sequence'
505--
507--