Selectively replace multiple instances of a character within a string: Difference between revisions

m
Line 158:
nthCharsReplaced ruleMap = snd . mapAccumL go M.empty
where
go a c =
|case M.memberlookup c ruleMap =of
| otherwise =Nothing -> (a, c)
Just ds ->
let i = fromMaybe 0 (M.lookup c a)
in ( M.insert c (succ i) a,
otherCharif i c< (fromMaybelength [] (M.lookup c ruleMap))ds
| i < length deltas = then fromMaybe c (deltasds !! i)
else c
)
| otherwise = (a, c)
 
otherChar :: Int -> Char -> [Maybe Char] -> Char
otherChar i c deltas
| i < length deltas = fromMaybe c (deltas !! i)
| otherwise = c
 
--------------------------- TEST -------------------------
9,655

edits