在Scala中,函数是第一公民。高阶函数中,我们经常将函数作为参数传递。怎样将一个方法转换成函数呢?使用”_”。
函数的两种使用方式:
func() // 调用一个函数
map(func) // 传递一个函数
def func(x: Double) = x
val x: Double = func() // return the functions's result
val function0: (Double) => Double = func _ // return the function's self