【问题标题】:Scala | operator '=>' and other these types of operator [duplicate]斯卡拉 |运算符'=>'和其他这些类型的运算符[重复]
【发布时间】:2016-10-24 13:14:21
【问题描述】:

可以帮助我理解这里使用或可能使用的代码和运算符类型

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

【问题讨论】:

  • 这不是操作员。搜索“按名称参数”。

标签: scala


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

此代码执行fx 次(我希望在您的代码中定义此变量)。基本上f 是一个函数,它将被执行给定(x)的次数。 阅读更多关于姓名呼唤的信息:Call by name vs call by value in Scala, clarification needed

【讨论】:

    猜你喜欢
    • 2011-01-22
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 2012-11-26
    • 2017-02-27
    • 2011-04-27
    相关资源
    最近更新 更多