scala - restrict implicit parameter resolution scope -
i find need write function inner recursive helper function, , takes same parameter list outer function, additional accumulator argument:
def encode(tree : tree, text: string):string = { def rec(tree: tree, text:string, result:string):string = ??? rec(tree, text, "") } i want simplify :
def encode(tree : tree, text: string)(implicit result:string = "" ):string this can remove inner function definition, has problem of that, see if need call function lookup inside encode, , lookup takes implicit parameter of type string, implicit result:string = "" implicitly pass lookup function.
def lookup(tree : tree, text: string)(implicit result:string = "" ):string i don't want happen, there way restrict implicit parameter in lookup resolving outside of function? or other better ideas?
how using normal default argument instead , passing accumulator explicitly in implementation:
def encode(tree : tree, text: string, result : string = "" ): string = { //snip encode(new_tree, new_text, new_result) } // call encode(my_tree, my_text)
Comments
Post a Comment