99-haskell-problems/Problems 01-10/problem_09.hs

11 lines
216 B
Haskell

pack :: (Eq a) => [a] -> [[a]]
pack =
foldr
( \x acc -> case acc of
[] -> [[x]]
(hd : tl) ->
if x == head hd
then (x : hd) : tl
else [x] : hd : tl
)
[]