Search code examples
parallel-processingkotlin

Parallel operations on Kotlin collections?


In Scala, one can easily do a parallel map, forEach, etc, with:

collection.par.map(..)

Is there an equivalent in Kotlin?


Solution

  • The Kotlin standard library has no support for parallel operations. However, since Kotlin uses the standard Java collection classes, you can use the Java 8 stream API to perform parallel operations on Kotlin collections as well.

    e.g.

    myCollection.parallelStream()
            .map { ... }
            .filter { ... }