@@ -84,6 +84,7 @@ module Streamly.Prelude
8484 -- number of steps can run concurrently. All of these can be expressed in
8585 -- terms of 'K.cons' and 'K.nil' primitives.
8686 , replicateM
87+ , replicate
8788 , K.repeat
8889 , repeatM
8990
@@ -257,7 +258,7 @@ import Prelude
257258 foldl, mapM, mapM_, sequence, all, any, sum, product, elem,
258259 notElem, maximum, minimum, head, last, tail, length, null,
259260 reverse, iterate, init, and, or, lookup, foldr1, (!!),
260− splitAt, scanl, scanl1)
261+ splitAt, scanl, scanl1, replicate)
261262import qualified Prelude
262263import qualified System.IO as IO
263264
@@ -419,6 +420,13 @@ replicateM n m = go n
419420 where
420421 go cnt = if cnt <= 0 then K.nil else m |: go (cnt - 1)
421422
423+-- | Generate a stream by replicating the value @n@ times.
424+--
425+replicate :: IsStream t => Int -> a -> t m a
426+replicate n a = go n
427+ where
428+ go cnt = if cnt <= 0 then K.nil else a `K.cons` go (cnt - 1)
429+
422430-- | Generate a stream by repeatedly executing a monadic action forever. Can be
423431-- expressed as @cycle1 . yieldM@.
424432--