:: Int -> [a] -> [[a]]

chunksOf n splits a list into length-n pieces. The last piece will be shorter if n does not evenly divide the length of the list. If n <= 0, chunksOf n l returns an infinite list of empty lists.
>>> chunksOf 3 [1..12]
[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
>>> chunksOf 3 "Hello there"
["Hel","lo ","the","re"]
>>> chunksOf 3 ([] :: [Int])
[]
Note that chunksOf n [] is [], not [[]]. This is intentional, and satisfies the property that
chunksOf n xs ++ chunksOf n ys == chunksOf n (xs ++ ys)
whenever n evenly divides the length of xs.
Produce all permutations of removing k elements from a list.
>>> removes 2 "abcdef"
["cdef","abef","abcd"]
Split a list into chunks of a given size. The last chunk may contain fewer than n elements. The chunk size must be positive.
chunksOf 3 "my test" == ["my ","tes","t"]
chunksOf 3 "mytest"  == ["myt","est"]
chunksOf 8 ""        == []
chunksOf 0 "test"    == undefined
>>> sliceHorizontal 6 ['a'..'z']
["agmsy","bhntz","ciou","djpv","ekqw","flrx"]
\(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceHorizontal n xs == transpose (sliceVertical n (xs::String))
\(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceVertical  n xs == transpose (sliceHorizontal n (xs::String))
The properties do not hold for empty lists because of:
>>> sliceHorizontal 4 ([]::[Int])
[[],[],[],[]]
>>> sliceVertical 6 ['a'..'z']
["abcdef","ghijkl","mnopqr","stuvwx","yz"]
Helper function to split a list in chunks Int length. Last chunk may be smaller.
Chop up a list in chunks of a given length. O(n).
Group a list of elements in the sublists of length i
Given a maximum length, splits a list into sublists
>>> chunksOf 5 (take 30 $ repeat 'a')
["aaaaa","aaaaa","aaaaa","aaaaa","aaaaa","aaaaa"]
Deprecated: Use XMonad.Prelude.chunksOf instead.
Generate all choices of n elements out of the list x with repetitions. "variation" seems to be used historically, but I like it more than "k-permutation".
>>> Comb.variateRep 2 "abc"
["aa","ab","ac","ba","bb","bc","ca","cb","cc"]
Generate all choices of n elements out of the list x without repetitions.
>>> Comb.variate 2 "abc"
["ab","ac","ba","bc","ca","cb"]

>>> Comb.variate 2 "abcd"
["ab","ac","ad","ba","bc","bd","ca","cb","cd","da","db","dc"]

>>> Comb.variate 3 "abcd"
["abc","abd","acb","acd","adb","adc","bac","bad","bca","bcd","bda","bdc","cab","cad","cba","cbd","cda","cdb","dab","dac","dba","dbc","dca","dcb"]
QC.forAll genVariate $ \xs -> Comb.variate (length xs) xs == Comb.permute xs
\xs -> equating (take 1000) (Comb.variate (length xs) xs) (Comb.permute (xs::String))
Generate all choices of n elements out of the list x respecting the order in x and without repetitions.
>>> Comb.tuples 2 "abc"
["ab","ac","bc"]

>>> Comb.tuples 2 "abcd"
["ab","ac","ad","bc","bd","cd"]

>>> Comb.tuples 3 "abcd"
["abc","abd","acd","bcd"]
Number of possibilities arising in rectification of a predicate in deductive database theory. Stefan Brass, "Logische Programmierung und deduktive Datenbanken", 2007, page 7-60 This is isomorphic to the partition of n-element sets into k non-empty subsets. http://oeis.org/A048993
>>> Comb.rectifications 4 "abc"
["aabc","abac","abbc","abca","abcb","abcc"]

>>> map (length . uncurry Comb.rectifications) $ do x<-[0..10]; y<-[0..x]; return (x,[1..y::Int])
[1,0,1,0,1,1,0,1,3,1,0,1,7,6,1,0,1,15,25,10,1,0,1,31,90,65,15,1,0,1,63,301,350,140,21,1,0,1,127,966,1701,1050,266,28,1,0,1,255,3025,7770,6951,2646,462,36,1,0,1,511,9330,34105,42525,22827,5880,750,45,1]
QC.forAll (QC.choose (0,7)) $ \k xs -> isAscending . Comb.rectifications k . nub . sort $ (xs::String)
Split the list into lists of n elements where n is the first parameter. Can be used efficiently just for the finite lists. Contains the modified code of the unfoldr function from the base package.
O(n). Splits a list into components of the given length. The last element may be shorter than the other chunks, depending on the length of the input.
>>> listChunksOf 3 [0..7]
[[0,1,2],[3,4,5],[6,7]]

>>> listChunksOf 0 [0..10]
[]

>>> listChunksOf (-13) [0..10]
[]

>>> listChunksOf 100 [1,2,3]
[[1,2,3]]
>>> P.take 2 $ listChunksOf 3 [1..]
[[1,2,3],[4,5,6]]
chunksOf n splits a vector into length-n pieces. The last piece will be shorter if n does not evenly divide the length of the vector. If n <= 0, chunksOf n l returns an infinite list of empty vectors. For example: Note that chunksOf n [] is [], not [[]]. This is intentional, and is consistent with a recursive definition of chunksOf; it satisfies the property that
chunksOf n xs ++ chunksOf n ys == chunksOf n (xs ++ ys)
whenever n evenly divides the length of xs.
Generalized version of replicateConcurrently.
Generalized version of replicateConcurrently.
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 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)
count n p parses n occurrences of p. If n is smaller or equal to zero, the parser equals to pure []. Returns a list of n parsed values.
count = replicateM
See also: skipCount, count'.