def mainCaller() = {
val name = "xyz"
someList.foreach { u:Map => foo(name, u) }
}
def foo(name:String)(map:Map): Unit = {
//match case....
//recursive call to foo in each case where name remains same, but map changes
}
如何将foo编写为部分应用函数,我不必在每次递归调用中传递名称并只调用foo(map1)
?
答案 0 :(得分:8)
两个选项:
def foo(name:String)(map:Map): Unit = {
val bar = foo(name)_
//match case...
// case 1:
bar(x)
// case 2:
bar(y)
}
或者:
def foo(name:String): Map => Unit = {
def bar(map: Map): Unit = {
//match case...
// case 1:
bar(x)
// case 2:
bar(y)
}
bar
}