I am doing some prototyping and I need a quick way to speed up some algorithm. So I was looking at Scala Parallel Collections. Without going into the details of why I need to use foreach
, can someone shed light on why the following crashes (just an example):
List(1,2,3,4).combinations(2).asParIterable.foreach(_ => println("foo"))
java.lang.ClassCastException: scala.collection.SeqLike$CombinationsItr cannot be
cast to scala.collection.parallel.ParIterable
at scala.collection.parallel.package$$anon$2.asParIterable(package.scala:70)
(Scala is 2.10.3)
Or in other words: How can I parallelize an iterator?