Skip to content

First class Function

HeatoN edited this page Jan 16, 2015 · 1 revision

Function在函数编程语言中是一等公民。 就是说Function可以像普通值一样被当参数传入或作为结果返回。

def sum(f: Int => Int): (Int, Int) => Int = 
  (a: Int, b: Int) => if (b <= a) b + sum(b+1, a) else 0

Clone this wiki locally