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

12 lines
216 B
Haskell
Raw Normal View History

2024-05-24 17:06:42 -05:00
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
)
[]