斯卡拉|运营商' =>'和其他这些类型的运营商

时间:2016-06-22 14:14:02

标签: scala

可以帮助我了解所使用的代码和运算符类型,或者可以在这里使用

def times [A](f: =>A): Unit={
def loop(current: Int): Unit=
    if(current > 0){
       f
     loop(current - 1)
    }
loop(x)
}

1 个答案:

答案 0 :(得分:1)

def times [A](f: =>A): Unit={ // f is call-by-name argument
def loop(current: Int): Unit // nested function inside of function types

此代码执行f x次(我希望在您的代码中定义此变量)。基本上f是一个函数,它将在给定(x)次数的情况下执行。 要详细了解按名称呼叫:Call by name vs call by value in Scala, clarification needed