I\'d like to know if there a elegant way to achieve something like that:
val l = Stream.from(1)
val parts = l.some_function(3) //any number
parts.foreach(
The only thing I can think of:
def distribute[T](n: Int)(x: Stream[T]) = (0 until n).map { p =>
x.zipWithIndex.collect {
case (e,i) if i % n == p => e
}
}
It's kind of ugly because each of the sub-streams has to entirely traverse the main-stream. But I don't think you can mitigate that while preserving (apparent) immutability.
Have you thought of dispatching individual tasks to actors and having a "task-distributer" that does exactly this?