on master help sign in
Add repeatM unfold
commitd15bde0085cf5eb600f32a70c9853d2cfdfc214f authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 20 Nov 2019, 16:41 (7 years ago) parent668a263
1 file changed+10
src/Streamly/Internal/Data/Unfold.hs+10
src/Streamly/Internal/Data/Unfold.hs+10
@@ -87,6 +87,7 @@ module Streamly.Internal.Data.Unfold
8787 , identity
8888 , const
8989 , replicateM
90+ , repeatM
9091 , fromList
9192 , fromListM
9293 , enumerateFromStepIntegral
@@ -404,6 +405,15 @@ replicateM n = Unfold step inject
404405 then Stop
405406 else Yield x (x, (i - 1))
406407
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+
407417-- | Convert a list of pure values to a 'Stream'
408418{-# INLINE_LATE fromList #-}
409419fromList :: Monad m => Unfold m [a] a