Suppose I need to replace few patterns in a string :
val rules = Map("abc" -> "123", "d" -> "4", "efg" -> "5"} // string to string
def replace(input:String, rules: Map[String, String] = {...}
replace("xyz", rules) // returns xyz
replace("abc123", rules) // returns 123123
replace("dddxyzefg", rules) // returns 444xyz5
How would you implement replace in Scala ? How would you generalize the solution for rules : Map[Regex, String] ?