<commit_before>module RunLength (decode, encode) where

import Control.Arrow (first, (&&&))
import Data.Char     (isNumber)
import Data.List     (group, partition)

encode :: String -> String
encode =
  concatMap (\(a, b) -> (if a /= "1" then a else "") ++ b)
    . fmap (show . length &&& (:[]) . head)
    . group

decode :: String -> String
decode = concatMap stitch . fmap (first read') . explode
  where read' i = if i == "" then 1 else read i

stitch :: (Int, Char) -> String
stitch (i, c) = replicate i c

explode :: String -> [(String, Char)]
explode [] = []
explode s  = let (i, s') = span isNumber s in (i, head s') : explode (tail s')<commit_msg>updates to haskell exercism prob<commit_after>module RunLength (decode, encode) where

import Control.Arrow (first, (&&&))
import Data.Char     (isDigit)
import Data.List     (group, partition)

encode :: String -> String
encode =
  concatMap (uncurry (++)) . fmap (show' . length &&& (:[]) . head) . group
  where show' n = if n == 1 then "" else show n

decode :: String -> String
decode = concatMap (uncurry replicate) . fmap (first read') . explode
  where read' i = if i == "" then 1 else read i

explode :: String -> [(String, Char)]
explode [] = []
explode s  = (i, head s') : explode (tail s') where (i, s') = span isDigit s
{'fraction_non_alphanumeric': 0.16602017067494182, 'fraction_numerical': 0.0031031807602792862, 'mean_word_length': 3.31438127090301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5995859', 'n_tokens_mistral': 437, 'n_tokens_neox': 428, 'n_words': 163}