Selectively replace multiple instances of a character within a string: Difference between revisions
Selectively replace multiple instances of a character within a string (view source)
Revision as of 17:26, 28 July 2022
, 1 year ago→{{header|Haskell}}
Line 158:
nthCharsReplaced ruleMap = snd . mapAccumL go M.empty
where
go a c
let i = fromMaybe 0 (M.lookup c a)
in ( M.insert c (succ i) a,
otherChar i c (fromMaybe [] (M.lookup c ruleMap))
)
| otherwise
otherChar :: Int -> Char -> [Maybe Char] -> Char
|