blob: b1904917763eea90e425614082de72c8a64c4f10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
pack :: (Eq a) => [a] -> [[a]]
pack = foldr elim []
where elim e [] = [[e]]
elim e p@(n:ns)
| e == head n = (e:n):ns
| otherwise = [e]:p
pack' (x:xs) = let (first,rest) = span (==x) xs
in (x:first) : pack' rest
pack' [] = []
pack'' (x:xs) = (x:takeWhile (==x) xs):(pack'' $ dropWhile (==x) xs)
pack'' [] = []
|