Skip to content

Instantly share code, notes, and snippets.

@crclark96
Created March 24, 2020 14:10
Show Gist options
  • Save crclark96/6a8e90a3e997e5fa3a180f1324ebdb40 to your computer and use it in GitHub Desktop.
Save crclark96/6a8e90a3e997e5fa3a180f1324ebdb40 to your computer and use it in GitHub Desktop.
l = ['a','a','b','b','b','c','c']
compress :: [Char] -> [String]
compress l = group l >>= (\x -> [take 1 x, show $ length x])
main = do
putStrLn . show $ compress l
/tmp
➜ runhaskell compress.hs
["a","2","b","3","c","2"]
@cassidoo
Copy link

So clean!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment