Skip to content

Instantly share code, notes, and snippets.

@comfly comfly/rle.hs
Created Jun 8, 2016

Embed
What would you like to do?
Run length encoding
module Main where
import Data.Foldable
rle = (concatMap (\(sym, num) -> sym:show num)) . foldr' collect []
where collect s [] = [(s, 1)]
collect s all@((sym, num):others)
| sym == s = (sym, num + 1):others
| otherwise = (s, 1):all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.