on master help sign in
Add repeatM unfold
d15bde0Harendra Kumar
src/Streamly/Internal/Data/Unfold.hs+10
@@ -87,6 +87,7 @@ module Streamly.Internal.Data.Unfold
87 , identity
87 , identity
88 , const
88 , const
89 , replicateM
89 , replicateM
90+ , repeatM
90 , fromList
91 , fromList
91 , fromListM
92 , fromListM
92 , enumerateFromStepIntegral
93 , enumerateFromStepIntegral
@@ -404,6 +405,15 @@ replicateM n = Unfold step inject
404 then Stop
405 then Stop
405 else Yield x (x, (i - 1))
406 else Yield x (x, (i - 1))
406
407
408+-- | Generates an infinite stream repeating the seed.
409+--
410+{-# INLINE repeatM #-}
411+repeatM :: Monad m => Unfold m a a
412+repeatM = Unfold step return
413+ where
414+ {-# INLINE_LATE step #-}
415+ step x = return $ Yield x x
416+
407-- | Convert a list of pure values to a 'Stream'
417-- | Convert a list of pure values to a 'Stream'
408{-# INLINE_LATE fromList #-}
418{-# INLINE_LATE fromList #-}
409fromList :: Monad m => Unfold m [a] a
419fromList :: Monad m => Unfold m [a] a