replicateM

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.
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
replicateM is a sequence counterpart of 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.
O(n) Execute the monadic action the given number of times and store the results in a vector.
O(n) Execute the monadic action the given number of times and store the results in a vector.
O(n) Execute the monadic action the given number of times and store the results in a vector.
The monadic version of replicateM.
>>> replicateM n = Stream.take n . Stream.repeatM
Generate a stream by performing a monadic action n times. Same as:
>>> pr n = threadDelay 1000000 >> print n
This runs serially and takes 3 seconds:
>>> Stream.drain $ Stream.fromSerial $ Stream.replicateM 3 $ pr 1
1
1
1
This runs concurrently and takes just 1 second:
>>> Stream.drain $ Stream.fromAsync  $ Stream.replicateM 3 $ pr 1
1
1
1
Concurrent
Like replicateM, but executing the action multiple times in parallel.
Create a mutable vector where the length is inferred from the type and fill it with values produced by repeatedly executing the monadic action.
O(n) Execute the monadic action n times and store the results in a vector where n is inferred from the type.
Create a mutable vector where the length is inferred from the type and fill it with values produced by repeatedly executing the monadic action.
Create a mutable vector where the length is inferred from the type and fill it with values produced by repeatedly executing the monadic action.
O(n) Execute the monadic action n times and store the results in a vector where n is inferred from the type.
O(n) Execute the monadic action n times and store the results in a vector where n is inferred from the type.
Create a mutable vector where the length is inferred from the type and fill it with values produced by repeatedly executing the monadic action.
O(n) Execute the monadic action n times and store the results in a vector where n is inferred from the type.
Create a mutable vector where the length is inferred from the type and fill it with values produced by repeatedly executing the monadic action.
O(n) Execute the monadic action n times and store the results in a vector where n is inferred from the type.