I’m just starting Scala and so getting my head around doing things in a more functional style.
Just wondering if there is a more functional way to achieve something like the following:
def expand(exp: String): String = {
var result = exp
for ((k,v) <- libMap) {result = result.replace(k, "(%s)".format(v))}
result
}
Or in general terms, given a string and some iterable collection, go through the collection and for every element, incrementally modify the input string.
Cheers
Generally the pattern
can be expressed functionally as
So for your case this becomas: