scala 高阶函数(一)
package com.cmcc.family.utils
import java.util.concurrent.TimeUnit
import com.google.common.base.Stopwatch
import org.apache.hadoop.hbase.client.Delete
import org.apache.hadoop.hbase.util.Bytes
import scala.collection.mutable
/**
* Created by Administrator on 2016/12/9 0009.
*/
object MainTest {
def sum(f: Int => Int)(a: Int, b: Int): Int = {
if (a > b) 0 else f(a) + sum(f)(a + 1, b)
}
def df(a: Int, b: Int)(c: Int): Int = a * b + c
def main(args: Array[String]) {
val df1: (Int) => Int = df(1, 2)
println(df1(3))//5
println(sum(df(1, 2))(1, 4))//18
println(sum(x => x + 3)(1, 4))//22
println(sum(x => x * x)(1, 4))//30
println(sum(x => x + x)(1, 4))//20
/* sum(x=>x*x)(1,4) => 1 + sum(x=>x*x)(2,4)
sum(x=>x*x)(2,4) => 4 + sum(x=>x*x)(3,4)
sum(x=>x*x)(3,4) => 9 + sum(x=>x*x)(4,4)
sum(x=>x*x)(4,4) => 16 + sum(x=>x*x)(5,4)
sum(x=>x*x)(5,4) => 0*/
}
}
scala 高阶函数使用技巧 陆续补充中。。。。