on master help sign in
Move definitions under doctest

So that we can at check them for compile errors.

commit81a3c948160ed7e68cce7921b661cf4e205425b3 authorHarendra Kumar <harendra@composewell.com> dateSat 7 Aug 2021, 04:42 (5 years ago) parent361c8f7
1 file changed+23−21
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+23−21
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+23−21
@@ -82,6 +82,11 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
8282--
8383-- $setup
8484-- >>> :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)
8590-- >>> import Prelude hiding (take, takeWhile, drop, reverse)
8691-- >>> import System.IO.Unsafe (unsafePerformIO)
8792-- >>> import qualified Streamly.Prelude as Stream
@@ -156,17 +161,18 @@ fromEffect = K.fromEffect
156161yieldM :: (Monad m, IsStream t) => m a -> t m a
157162yieldM = fromEffect
158163-- |
159−-- @
160−-- repeatM = fix . consM
161−-- repeatM = cycle1 . fromEffect
162−-- @
164+-- >>> repeatM = fix . consM
165+-- >>> repeatM = cycle1 . fromEffect
163166--
164167-- Generate a stream by repeatedly executing a monadic action forever.
165168--
166−-- @
167−-- drain $ fromSerial $ S.take 10 $ S.repeatM $ (threadDelay 1000000 >> print 1)
168−-- drain $ fromAsync $ S.take 10 $ S.repeatM $ (threadDelay 1000000 >> print 1)
169−-- @
169+-- >>> :{
170+-- repeatAsync =
171+-- Stream.repeatM (threadDelay 1000000 >> print 1)
172+-- & Stream.take 10
173+-- & Stream.fromAsync
174+-- & Stream.drain
175+-- :}
170176--
171177-- /Concurrent, infinite (do not use with 'fromParallel')/
172178--
@@ -444,11 +450,11 @@ interjectSuffix n f xs = xs `Par.parallelFst` repeatM timed
444450-- /Note:/ 'reverse'' is much faster than this, use that when performance
445451-- matters.
446452--
447−-- > reverse = S.foldlT (flip S.cons) S.nil
448−--
449453-- | Returns the elements of the stream in reverse order. The stream must be
450454-- finite. Note that this necessarily buffers the entire stream in memory.
451455--
456+-- >>> reverse = Stream.foldlT (flip Stream.cons) Stream.nil
457+--
452458-- /Since 0.7.0 (Monad m constraint)/
453459--
454460-- /Since: 0.1.1/
@@ -480,12 +486,10 @@ concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
480486-- | Map a stream producing function on each element of the stream and then
481487-- flatten the results into a single stream.
482488--
483−-- @
484−-- concatMap f = 'concatMapM' (return . f)
485−-- concatMap = 'concatMapWith' 'Serial.serial'
486−-- concatMap f = 'concat . map f'
487−-- concatMap f = 'unfoldMany' (UF.lmap f UF.fromStream)
488−-- @
489+-- >>> concatMap f = Stream.concatMapM (return . f)
490+-- >>> concatMap f = Stream.concatMapWith Stream.serial f
491+-- >>> concatMap f = Stream.concat . Stream.map f
492+-- >>> concatMap f = Stream.unfoldMany (Unfold.lmap f Unfold.fromStream)
489493--
490494-- @since 0.6.0
491495{-# INLINE concatMap #-}
@@ -495,11 +499,9 @@ concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
495499-- | Given a stream value in the underlying monad, lift and join the underlying
496500-- monad with the stream monad.
497501--
498−-- @
499−-- concatM = concat . fromEffect
500−-- concatM = concat . lift -- requires @(MonadTrans t)@
501−-- concatM = join . lift -- requires @(MonadTrans t@, @Monad (t m))@
502−-- @
502+-- >>> concatM = Stream.concat . Stream.fromEffect
503+-- >>> concatM = Stream.concat . lift -- requires (MonadTrans t)
504+-- >>> concatM = join . lift -- requires (MonadTrans t, Monad (t m))
503505--
504506-- See also: 'concat', 'sequence'
505507--