replicate -package:Cabal -package:containers -package:bytestring -is:exact -package:text -package:hedgehog package:base

replicate n x is a list of length n with x the value of every element. It is an instance of the more general genericReplicate, in which n may be of any integral type.

Examples

>>> replicate 0 True
[]
>>> replicate (-1) True
[]
>>> replicate 4 True
[True,True,True,True]
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)
Like replicateM, but discards the result.

Examples

>>> replicateM_ 3 (putStr "a")
aaa
The genericReplicate function is an overloaded version of replicate, which accepts any Integral value as the number of repetitions to make.