This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |