partitionedMap

fun <E, R> List<E>.partitionedMap(partitions: Int, body: (List<E>, (List<R>) -> Unit) -> Unit, after: (List<R>) -> Unit)

Partition the receiver into partitions approximately equal sublists. Some may be empty if count is larger than the receiver's size. Invoke the supplied body for each sublist. The body must eventually, perhaps in another Thread, invoke a function passed to it, to indicate completion, and to provide a list containing the element-wise transformation of the original sublist. These transformed sublists are then concatenated to form a new list, which is passed to the after function, perhaps in another Thread.

The original calling thread returns after each body returns, not after the bodies call their completion function, so if they offload the responsibility to run the completion function to another thread, that may be where the after function is executed as well. If no offloading happens, the original thread will run the after function.