I have the following Kotlin code, which is a simplification of my problem:
val baseBuilder : Builder =
Builder("xx")
.setA("aa")
.setB("bb")
fun f(action: Action): Builder {
var extraBuilder = baseBuilder
.add(action)
return extraBuilder
}
If I call f many times I end up with a builder having many actions added to it, but I want f to return a builder that has only one action. I can't change the implementation of that Builder class. I thought of making a copy of the baseBuilder inside the f function but I couldn't find how. Or maybe I can achieve what I want in other way?