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

m
Line 192:
 
nthCharsReplaced :: M.Map Char [Maybe Char] -> String -> String
nthCharsReplaced ruleMap = snd . mapAccumL go M.emptyruleMap
where
go a c =
case M.lookup c ruleMapa of
Nothing -> (a, c)
Just ds ->
letif inull = fromMaybe 0 (M.lookup c a)ds
in then ( M.inserta, c (succ i) a,
if i < length dselse
( M.adjust then fromMaybetail c (ds !! i)a,
fromMaybe c else(head cds)
)
 
9,655

edits