I constantly find I need to write function with inner recursive helper function, and it takes the same parameter list as its outer function, but only an additional accumulator argument:
def encode(tree : Tree, text: String):String = {
def rec(tree: Tree, text:String, result:String):String = ???
rec(tree, text, "")
}
I want to simplify this into :
def encode(tree : Tree, text: String)(implicit result:String = "" ):String
this can remove the inner function definition, but it has a problem of that, see if I need to call a function lookup inside encode, and lookup also takes implicit parameter of type String, the implicit result:String = "" implicitly pass to lookup function.
def lookup(tree : Tree, text: String)(implicit result:String = "" ):String
I don't want this happen, is there a way to restrict the implicit parameter in lookup from resolving outside of that function? Or other better ideas?
maxListImpParmexample, basically it means, the method has some additional information I want to pass, here the information is an accumulator. The problem here, is not this pattern, it happens anywhere you have implicit parameters, it just passed implicitly sometimes this is against my intention, if thelookupis not defined by me, I might have not known, the parameter had ever passed to it.