==================================== scala val files = List("/path/to/file1.txt", "/path/to/file2.txt", ...) scala val wordCounts = files.par.flatMap(file => { scala.io.Source.fromFile(file).getLines().flatMap(_.split(" ")) }).groupBy(word => word).mapValues(_.size) scala wordCounts.foreach(println) - Scala Parallel Collections: [https://docs.scala-lang.org/overviews/parallel-collections/overview.html](https://docs.scala-lang.org/overviews/parallel-collections/overview.html) - Scala Parallel Collections API Documentation: [https://www.scala-lang.org/api/current/scala/collection/parallel/mutable/package.html](https://www.scala-lang.org/api/current/scala/collection/parallel/mutable/package.html)


上一篇:
下一篇:
切换中文