fragment.hs

Haskell

Public Domain

Splits a list into contiguous sublists of fixed length

Download (right click, save as, rename as appropriate)

Embed

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)