Splits a list into contiguous sublists of fixed length
Download (right click, save as, rename as appropriate)
1 2 3 4 5
-- |@fragment n list@ splits @list@ into contiguous sublists of length @n@ -- (though the last list may be short). fragment :: Int -> [a] -> [[a]] fragment _ [] = [] fragment n list = take n list : fragment n (drop n list)