Creating a parallel collection w/2.8
I'd like to do something like this:
(1 to 100).parallel(20).filter(_ > 20).foreach(sendViaHttp)
List(1,3,5,9,100).parallel(3).map(fetchFromDatabase)
This means, "take a collection, create a thread pool with N threads, and run filter etc in that thread pool". My understanding of 2.8 collecti开发者_StackOverflow社区ons (and scala in general) is sketchy. I've fiddled with CanBuildFrom, but I'm pretty certain either what I'm doing is wrong, or is just a bad idea.
Can someone help with some examples or pointers?
Aggregating the comments to an acceptable answer:
If you can switch to Scala 2.9 which has build-in parallel collections
If you want to control the amount of parallel threads you can do so using the advice here.
精彩评论