scala 实现WordCount
2016-08-16 18:00
363 查看
object WC {
def main(args: Array[String]): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map((_,1))
.groupBy(_._1)
.mapValues(_.map(_._2).reduce(_+_))
list.foreach(println(_))
val l = List(1,2,3,4,5,6,7,8,9)
val sum = l.reduce{_+_}
println("sum=>"+sum)
}
def WC(): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map { x => (x,1) }
.groupBy(x=>x._1)
.mapValues{
list=>list.map(i=>i._2).reduce((x,y)=>x+y)
}
list.foreach(x=>println(x))
}
def WC2(): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map { x => (x,1) }
.groupBy(x=>x._1)
.mapValues(list=>list.map(i=>i._2))
.mapValues(l => l.reduce((x,y)=>x+y))
list.foreach(x=>println(x))
}
}
def main(args: Array[String]): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map((_,1))
.groupBy(_._1)
.mapValues(_.map(_._2).reduce(_+_))
list.foreach(println(_))
val l = List(1,2,3,4,5,6,7,8,9)
val sum = l.reduce{_+_}
println("sum=>"+sum)
}
def WC(): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map { x => (x,1) }
.groupBy(x=>x._1)
.mapValues{
list=>list.map(i=>i._2).reduce((x,y)=>x+y)
}
list.foreach(x=>println(x))
}
def WC2(): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map { x => (x,1) }
.groupBy(x=>x._1)
.mapValues(list=>list.map(i=>i._2))
.mapValues(l => l.reduce((x,y)=>x+y))
list.foreach(x=>println(x))
}
}
相关文章推荐
- Spark:用Scala和Java实现WordCount
- Scala 学习(六)--- 单机实现wordcount详细解读
- Akka初体验之scala版word-count 的实现
- Spark:用Scala和Java实现WordCount
- Spark:用Scala和Java实现WordCount
- WordCount的Scala实现
- Flink学习笔记 --- scala实现Flink的DataSet Source进行WordCount
- 用scala实现wordcount
- Spark:用Scala和Java实现WordCount
- 使用 scala 实现单机版 WordCount
- 快学Scala-Actor并发编程实现WordCount
- Spark:用Scala和Java实现WordCount
- Spark 程序 WordCount实现 Scala、Python
- maven构建Scala程序,实现spark的wordcount
- python、scala、java分别实现在spark上实现WordCount
- scala实现wordcount
- Scala实现WordCount功能
- java和scala分别实现WordCount
- Spark:用Java和Scala实现WordCount
- Python+Hadoop Streaming实现MapReduce(word count)