blob: 77b7295d77c4b242e522a27f0e41a8569ba13972 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import Control.Arrow
import Data.List
data ListItem a = Single a | Multiple a Int
deriving (Show)
encode :: Eq a => [a] -> [(a,Int)]
encode xs = map (head &&& length) $ group xs
encodeModified :: Eq a => [a] -> [ListItem a]
encodeModified = map helper . encode
where
helper (a,1) = Single a
helper (a,c) = Multiple a c
|