I want to perform several ordered and successive replaceAll(...,...) on a string in a functional way in scala.
What\'s the most elegant solution ? Scalaz welcome ! ;
If its just a few invocations then just chain them. Otherwise I guess I'd try this:
Seq("a" -> "b", "b" -> "a").foldLeft("abab"){case (z, (s,r)) => z.replaceAll(s, r)}
Or if you like shorter code with confusing wildcards and extra closures:
Seq("a" -> "b", "b" -> "a").foldLeft("abab"){_.replaceAll _ tupled(_)}