title: Is `group list by size` a fold?
body: <p>I came across this problem : grouping the elements of a list by packet of the same size, so that</p>
  
  <pre><code>&gt; groupBy 3 [1..10] 
  [[1,2,3], [4,5,6], [7,8,9], [10]]
  </code></pre>
  
  <p>Nothing really hard to do, but first I was surprise that I couldn't find a function for it.
  My first try was</p>
  
  <pre><code> groupBy _ [] = []
   groupBy n xs = g : groupBy n gs
                where (g, gs) = splitAt n xs
  </code></pre>
  
  <p>So far so good, it works, even on infinite list. However I don't like the first line <code>groupBy _ [] = []</code>. Seems a good candidate for a fold but I couldn't figure it out. </p>
  
  <p>So can this function can be written as a fold or as a one liner ?</p>
  
  <h1>Update</h1>
  
  <p>My attempt at a one liner:</p>
  
  <pre><code>groupBy' n l = map (map snd) $ groupBy ((==) `on` fst) $ concatMap (replicate n) [1..] `zip` l
  </code></pre>
  
  <p>It took me 10 times more to write that the initial attempt.</p>
  
  <h1>Update 2</h1>
  
  <p>Following Ganesh answer and using <code>unfoldr</code> and the help of <code>pointfree</code> I came out with this convoluted point free solution</p>
  
  <pre><code>groupBy' n = unfoldr $ listToMaybe . (ap (&gt;&gt;) (return.splitAt n))
  </code></pre>