.

1
2
3
4
5
6
-- *** 5
mygroupBy eq xs = foldr step [] xs
    where step x [] = [[x]]
          step x (y:ys)
              | eq x (head y) = [x:y] ++ ys
              | otherwise     = [x] : y : ys