module Runlength where
--splitWhen p (x:xs)
-- | p x = ([], x:xs)
-- | otherwise = (x:a, b)
-- where (a,b) = splitWhen p xs
splitWhen p (x:xs)
| p x = ([], x:xs)
| otherwise = (\(a,b) -> (x:a, b)) $ splitWhen p xs
splitWhen _ _ = ([], [])
group [] = []
group xs@(x:_) = a : group b
where (a,b) = splitWhen (/= x) xs
encode [] = []
encode xs = map (\(x:xs) -> (x, length (x:xs))) (group xs)