部分应用函数,在调用函数的时候,只传入一部分参数。
那么下列代码将说明:
object Base59 {
val getMax = (x:Int,y:Int) => if(x>y) x else y
val getMin = (x:Int,y:Int) => if(x<y) x else y
val test = (x: (Int,Int)=>Int,a:Int,b:Int ) => {
println("test被调用")
println(x(a,b))
}
def main(args: Array[String]): Unit = {
test(getMax, 1, 2)
test(getMin,1,2)
}
}
上述代码结果:
test被调用
2
test被调用
1
object Base60 {
val mul = (a:Int,b:Int,c:Int) => a * b * c
def main(args: Array[String]): Unit = {
val rst = mul(2,3,4)
val f = mul(2,3,_)
var rst1 = f(5)
println(rst)
println(rst1)
}
}
上述代码结果:
24
30