Map on parallel range

I am using parallel collections in Scala 2.12.3. When I run the following code using the interactive Scala shell:
0.until(10).par.map(x => x+1)
it does not terminate, but the following code terminates and returns the correct result:
0.until(10).map(x => x+1).par
Both work correctly in compiled Scala.
Is this a bug? Of course I can always use the latter but the former should also work.
Thanks

According to https://github.com/scala/scala-parallel-collections/issues/34 try providing repl-class-based flag

scala -Yrepl-class-based

If you are using sbt console then according to https://stackoverflow.com/a/57630521/5205022 try

sbt 'set Compile/console/scalacOptions += "-Yrepl-class-based"' console

I believe since Scala 2.13.2 has the flag set by default https://github.com/scala/scala/pull/8748 so it should work out-of-the box.

2 Likes