I have this function to convert an Array
to a ParArray
, giving the number of threads as parameter:
def parN[T](collection: Array[T], n: Int) = {
val parCollection = collection.par
parCollection.tasksupport = new ForkJoinTaskSupport(
new concurrent.forkjoin.ForkJoinPool(n))
parCollection
}
Now I'd like to make this generic, such that it works with collections other than Array
:
def parN[S, T[S] <: Parallelizable[S, ParIterable[S]]](collection: T[S], n: Int) = {
val parCollection = collection.par
parCollection.tasksupport = new ForkJoinTaskSupport(
new concurrent.forkjoin.ForkJoinPool(n))
parCollection
}
But when I call it with parN(Array(1, 2, 3), 2)
, I get this error:
inferred type arguments [Int,Array] do not
conform to method parN's type parameter bounds
[S,T[S] <: scala.collection.Parallelizable[S,scala.collection.parallel.ParIterable[S]]]
On the other hand, this is working:
val x: Parallelizable[Int, ParIterable[Int]] = Array(1, 2, 3)
Any ideas what might be wrong with my type parameters?