@@ -84,6 +84,7 @@ module Streamly.Prelude
84 -- number of steps can run concurrently. All of these can be expressed in
84 -- number of steps can run concurrently. All of these can be expressed in
85 -- terms of 'K.cons' and 'K.nil' primitives.
85 -- terms of 'K.cons' and 'K.nil' primitives.
86 , replicateM
86 , replicateM
87 , K.repeat
88 , K.repeat
@@ -257,7 +258,7 @@ import Prelude
257 foldl, mapM, mapM_, sequence, all, any, sum, product, elem,
258 foldl, mapM, mapM_, sequence, all, any, sum, product, elem,
258 notElem, maximum, minimum, head, last, tail, length, null,
259 notElem, maximum, minimum, head, last, tail, length, null,
259 reverse, iterate, init, and, or, lookup, foldr1, (!!),
260 reverse, iterate, init, and, or, lookup, foldr1, (!!),
260− splitAt, scanl, scanl1)
261+ splitAt, scanl, scanl1, replicate)
261import qualified Prelude
262import qualified Prelude
262import qualified System.IO as IO
263import qualified System.IO as IO
@@ -419,6 +420,13 @@ replicateM n m = go n
420 go cnt = if cnt <= 0 then K.nil else m |: go (cnt - 1)
421 go cnt = if cnt <= 0 then K.nil else m |: go (cnt - 1)
423+-- | Generate a stream by replicating the value @n@ times.
425+replicate :: IsStream t => Int -> a -> t m a
428+ go cnt = if cnt <= 0 then K.nil else a `K.cons` go (cnt - 1)
422-- | Generate a stream by repeatedly executing a monadic action forever. Can be
430-- | Generate a stream by repeatedly executing a monadic action forever. Can be
423-- expressed as @cycle1 . yieldM@.
431-- expressed as @cycle1 . yieldM@.