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 =
if| M.member c ruleMap =
then
let i = fromMaybe 0 (M.lookup c a)
in ( M.insert c (succ i) a,
otherChar i c (fromMaybe [] (M.lookup c ruleMap))
)
| otherwise else= (a, c)
 
otherChar :: Int -> Char -> [Maybe Char] -> Char
9,655

edits