如何以编程方式减少curried函数?

时间:2018-03-08 13:49:37

标签: scala functional-programming user-defined-functions

如何通过递归2次来减少函数? 2是变量,明天可以是3。我认为没有办法做到这一点。我已经阅读了几篇关于堆栈溢出的帖子,没有人这样做。这基本上是一段功能代码,试图生成一个udf。

def lookupAndCreateColumn(allColNames:Seq[String])(column4:String)(column3:String)(column2:String)(column1:String):String = {

"somestring"
}
val allColNames= List("a","b")
var lookupCreateColCurried = lookupAndCreateColumn(allColNames.toList) _



def callFuncRecursively(func:Any,callMax:Int,curryArg:String) = {
    def callFunc(func:Any,callMax:Int,curryArg:String,incr:Int):Object = {
        if(incr==callMax) func else {
           val p = incr + 1
           callFunc(func(curryArg),callMax,curryArg,p)
        }
    }
    callFunc(func,callMax,curryArg,0)
}

callFuncRecursively(lookupCreateColCurried,2,"not_defined")

0 个答案:

没有答案