Parallel iterator in Scala

前端 未结 4 1027
自闭症患者
自闭症患者 2020-12-06 00:43

Is it somehow possible, using Scala\'s parallel collections to parallelize an Iterator without evaluating it completely beforehand?

Here I am t

4条回答
  •  旧时难觅i
    2020-12-06 01:26

    I realize that this is an old question, but does the ParIterator implementation in the iterata library do what you were looking for?

    scala> import com.timgroup.iterata.ParIterator.Implicits._
    scala> val it = (1 to 100000).toIterator.par().map(n => (n + 1, Thread.currentThread.getId))
    scala> it.map(_._2).toSet.size
    res2: Int = 8 // addition was distributed over 8 threads
    

提交回复
热议问题