Parallel iterator in Scala

前端 未结 4 1026
自闭症患者
自闭症患者 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条回答
  •  感动是毒
    2020-12-06 01:22

    It's a bit hard to follow exactly what you're after, but perhaps it's something like this:

    val f = (x: Int) => x + 1
    val s = (0 to 9).toStream map f splitAt(6) match { 
      case (left, right) => left.par; right 
    }
    

    This will eveluate f on the first 6 elements in parallel and then return a stream over the rest.

提交回复
热议问题