質問

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)?

役に立ちましたか?

解決

2つのオプション:

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
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top