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.