replicateM -package:streamly

replicateM n act performs the action act n times, and then returns the list of results.
replicateM n (pure x) == replicate n x

Examples

>>> replicateM 3 getLine
hi
heya
hiya
["hi","heya","hiya"]
>>> import Control.Monad.State

>>> runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1
([1,2,3],4)
replicateM is the Seq counterpart of Control.Monad.replicateM.
replicateM n x = sequence (replicate n x)
For base >= 4.8.0 and containers >= 0.5.11, replicateM is a synonym for replicateA.
O(n) Execute the monadic action the given number of times and store the results in a vector.
Yield a Bundle of values obtained by performing the monadic action the given number of times
O(n) Execute the monadic action the given number of times and store the results in a vector.
Create a mutable vector of the given length (0 if the length is negative) and fill it with values produced by repeatedly executing the monadic action.
Create a mutable vector of the given length (0 if the length is negative) and fill it with values produced by repeatedly executing the monadic action.
O(n) Execute the monadic action the given number of times and store the results in a vector.
Create a mutable vector of the given length (0 if the length is negative) and fill it with values produced by repeatedly executing the monadic action.
O(n) Execute the monadic action the given number of times and store the results in a vector.
Create a mutable vector of the given length (0 if the length is negative) and fill it with values produced by repeatedly executing the monadic action.
O(n) Execute the monadic action the given number of times and store the results in a vector.
Create a mutable vector of the given length (0 if the length is negative) and fill it with values produced by repeatedly executing the monadic action.
Perform the given action n times, yielding each result. Subject to fusion
Replicate a monadic value the given number of times. Subject to fusion Since 1.2.0
Repeat a monadic action a fixed number of times, yielding each result
replicateM  0      x = return ()

replicateM (m + n) x = replicateM m x >> replicateM n x  -- 0 <= {m,n}
replicateM :: Monad m => Int -> m a -> Producer a m ()
replicateM n act performs the action act n times, and then returns the list of results:

Examples

>>> import Control.Monad.State

>>> runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1
([1,2,3],4)
Repeat an action several times, streaming its results.
>>> S.print $ S.replicateM 2 getCurrentTime
2015-08-18 00:57:36.124508 UTC
2015-08-18 00:57:36.124785 UTC
The monadic version of replicateM.
Like replicateM, but executing the action multiple times in parallel.