高阶函数、wordcount

This commit is contained in:
2019-01-03 10:41:59 +08:00
parent 71891ab92b
commit 64d38840d9
2 changed files with 24 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
package top.fjy8018.scala
import scala.io.Source
/**
* F嘉阳
* 2018-11-25 20:21

View File

@@ -0,0 +1,22 @@
package top.fjy8018.scala
import scala.io.Source
/**
* wordcount
* F嘉阳
* 2019-01-03 10:33
*/
object WordCount {
def main(args: Array[String]): Unit = {
wordCount()
}
def wordCount(): Unit ={
val txt = Source.fromFile("tmp/hello.txt").mkString
val txts = List(txt)
txts.flatMap(_.split(",")).map(x => (x,1)).groupBy(_._1).mapValues(_.size).foreach(println)
}
}