group (x:xs) = let (first,rest) = span (==x) xs in (x:first) : group rest group [] = []