Splitting lists inside list haskell

Posted by user3713267 on Stack Overflow See other posts from Stack Overflow or by user3713267
Published on 2014-06-06T08:46:14Z Indexed on 2014/06/07 9:25 UTC
Read the original article Hit count: 270

Filed under:
|

Hi I need to split list by an argument in Haskell. I found function like this

group :: Int -> [a] -> [[a]]
group _ [] = []
group n l
  | n > 0 = (take n l) : (group n (drop n l))
  | otherwise = error "Negative n"

But what if lists that I want to divide are contained by another list?

For example

group 3 [[1,2,3,4,5,6],[2,4,6,8,10,12]]

should return

[[[1,2,3],[4,5,6]],[[2,4,6],[8,10,12]]]

Is there any way to do that ?

© Stack Overflow or respective owner

Related posts about list

Related posts about haskell