Scala 函数柯里化

1、代码

package com.yy.base

/**
 * 函数柯里化
 */
object CurringFuncTest {
  def main(args: Array[String]): Unit = {
    
    //正常定义1
    def multiple1(x:Int,y:Int) = x*y
    println(multiple1(2,3))
    //其中一个函数作为返回值
    def multiple2(x:Int)=(y:Int)=>x*y
    println(multiple2(3)(4))
    
    //柯里化
    def multiple3AfterCurring(x:Int)(y:Int) = x*y
    println(multiple3AfterCurring(4)(5)) //必须传递两个参数,否则编译报错
    
    val a = Array("XX","YY")
    val b = Array("xx","yy")
    println(a.corresponds(b)(_.equalsIgnoreCase(_)))
  }
}
2、结果

6
12
20
true

你可能感兴趣的:(scala,柯里化)