9512.net

# 03 3000门徒 第三课 SCALA函数式编程彻底精通及SPARK源码阅读

1.

2.

3.

4.

5.

6.

val arr2 = Array("A", "B", "C") println(arr1.corresponds(arr2)(_ equalsIgnoreCase _)) //柯里化实例 val arr1 = Array("a", "b", "c") val arr2 = Array("A", "B", "C") def eq(a:String,b:String)={ a.toLowerCase() == b.toLowerCase() } println(arr1.corresponds(arr2)(eq(_,_)))

1.

def wordCount(dir: String) = { val wordCountMap = scala.collection.mutable.Map[String, Int]() val fileList = ListBuffer[File]() getAllFilesFromDir(dir, fileList) def seqop = (m1:scala.collection.mutable.HashMap[String,Int],word:(String,Int))=>{ m1(word._1) = m1.getOrElse(word._1,0)+word._2 m1 } def combop = (m1:scala.collection.mutable.HashMap[String,Int],m2:scala.collection.mutable.HashMap[String,Int])=>{

for((k,v)<-m1){ m2(k) = m2.getOrElse(k, 0)+v } m2 } val wordcount = fileList.flatMap(file => { val lines = Source.fromFile(file).getLines val words = lines.flatMap(line => line.split(" ")) words }).map((_,1)).aggregate(scala.collection.mutable.HashMap[String,Int]())(seqop, combop) println(wordcount) }

## 相关文档：

Scala深入浅出实战经典---基础入门_编程语言_教学视频...

...第二课-Scala面向对象彻底精通及Spark源码阅读.
02-3000门徒-第二课-Scala面向对象彻底精通及Spark源码阅读._计算机软件及应用_IT/计算机_专业资料。02-3000门徒-第二课-Scala面向对象彻底精通及Spark源码阅读....