<commit_before>module RunLength (decode, encode) where

import Data.Char (isDigit)
import Data.List (group, groupBy)

decode :: String -> String
decode = concatMap (uncurry replicate) . foldPairs

foldPairs :: String -> [(Int, Char)]
foldPairs = snd . foldl buildPairs (Nothing, []) . groupBy allNumbers

buildPairs :: (Maybe String, [(Int, Char)]) -> String -> (Maybe String, [(Int, Char)])
buildPairs (Just previousNumber, list) group
  = (Nothing, list ++ [(read previousNumber, head group)])
buildPairs (Nothing, list) group
  | (isDigit . head) group = (Just group, list)
  | otherwise = (Nothing, list ++ [(1, head group)])

allNumbers a b = isDigit a && isDigit b

encode :: String -> String<commit_msg>added typings<commit_after>module RunLength (decode, encode) where

import Data.Char (isDigit)
import Data.List (group, groupBy)

decode :: String -> String
decode = concatMap (uncurry replicate) . foldPairs

foldPairs :: String -> [(Int, Char)]
foldPairs = snd . foldl listToPairs (Nothing, []) . groupBy allNumbers

listToPairs :: (Maybe String, [(Int, Char)]) -> String -> (Maybe String, [(Int, Char)])
listToPairs (Just previousNumber, list) group
  = (Nothing, list ++ [(read previousNumber, head group)])
listToPairs (Nothing, list) group
  | (isDigit . head) group = (Just group, list)
  | otherwise = (Nothing, list ++ [(1, head group)])

allNumbers :: Char -> Char -> Bool
allNumbers a b = isDigit a && isDigit b

encode :: String -> String
{'fraction_non_alphanumeric': 0.14667580534612748, 'fraction_numerical': 0.0013708019191226869, 'mean_word_length': 4.593869731800766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1106', 'n_tokens_mistral': 480, 'n_tokens_neox': 461, 'n_words': 160}