Skip to content

Instantly share code, notes, and snippets.

-- Simple approach to grouping a list of items by being both contiguous and equal
-- The aim is to take a list of items, check each item sequentially to see if it is the same
-- as the last item.
-- Separates a list like this: [1,2,2,2,3,3,4,4,1,1,2,2] => [[1],[2,2,2],[3,3],[4,4],[1,1],[2,2]]
separate' :: Eq a => [a] -> Int -> [[a]]
separate' (x0 : xs@(x1 : _)) n
| x0 == x1 = separate' xs (n + 1)