scala currying

  def threeNumberSum(x: Int, y: Int, z: Int) = x + y + z

  def threeNumberSumCurrying(x: Int)(y: Int)(z: Int) = x + y + z

  def twoNumberSum = threeNumberSumCurrying(1)_
  
  assert(threeNumberSumCurrying(1)(2)(3) == threeNumberSum(1, 2, 3))
  assert(twoNumberSum(2)(3) == threeNumberSum(1, 2, 3))


自己习惯了java这类指令编程模式的静态语言,也只对java比较熟悉,第一次看到currying觉得眼前一亮,给代码编写带来了不少新特性

你可能感兴趣的:(scala)