高阶函数、wordcount
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package top.fjy8018.scala
|
package top.fjy8018.scala
|
||||||
|
|
||||||
|
import scala.io.Source
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* F嘉阳
|
* F嘉阳
|
||||||
* 2018-11-25 20:21
|
* 2018-11-25 20:21
|
||||||
|
|||||||
22
src/main/scala/top/fjy8018/scala/WordCount.scala
Normal file
22
src/main/scala/top/fjy8018/scala/WordCount.scala
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user