Skip to content

Instantly share code, notes, and snippets.

@harukizaemon
Created December 29, 2011 13:28
Show Gist options
  • Select an option

  • Save harukizaemon/1534113 to your computer and use it in GitHub Desktop.

Select an option

Save harukizaemon/1534113 to your computer and use it in GitHub Desktop.
Take n elements of a list at a time
chunk _ [] = []
chunk n xs
| n < 1 = []
| otherwise = first:chunk n remainder
where (first, remainder) = splitAt n xs
-- ghci> chunk 3 [1,2,3,4,5,6,7,8,9,0]
-- [[1,2,3],[4,5,6],[7,8,9],[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment