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

m
Line 153:
import Data.Maybe (fromMaybe)
 
---------- POSITIONAL CHARACTER -REPLACEMENT RULES --------
 
nthCharsReplaced :: M.Map Char [Maybe Char] -> String -> String
Line 159:
where
go a c =
letif i = fromMaybe 0 (M.lookupmember c a)ruleMap
in ( M.insert c (succ i) a,then
otherCharlet i c= (fromMaybe []0 (M.lookup c ruleMap)a)
in ( M.insert c (succ i) a,
otherChar i c (fromMaybe [] (M.lookup c ruleMap))
)
else (a, c)
 
otherChar :: Int -> Char -> [Maybe Char] -> Char
Line 168 ⟶ 171:
| i < length deltas = fromMaybe c (deltas !! i)
| otherwise = c
 
 
--------------------------- TEST -------------------------
9,655

edits