_parallel

trait _parallel
class java.lang.Object
trait scala.Matchable
class Any
trait _build
object ~

Def

def parallel[A]: ~~.Flow[A]

Parallel

Parallel

Returns ~~.Flow with parallel execution

Each consecutive element will be sent to a new thread for processing

  (1 <> 5).~
     .parallel
     .map("Value: " + _ + "\t" + Thread.currentThread.getName)
     .foreach(println)

  // Possible Output
  Value: 1    ForkJoinPool.commonPool-worker-9
  Value: 3    ForkJoinPool.commonPool-worker-11
  Value: 2    main
  Value: 4    ForkJoinPool.commonPool-worker-2
  Value: 5    ForkJoinPool.commonPool-worker-4
Source
_parallel.scala
def parallelIf[A](v: Boolean): ~~.Flow[A]

Conditionally parallel

Conditionally parallel

Returns ~~.Flow with parallel or sequential implementation, depending on given parameter

   (1 <> 50).~.parallelIf(true).isParallel   // Returns true

   (1 <> 50).~.parallelIf(false).isParallel  // Returns false
Source
_parallel.scala
def parallelIfOver[A](threshold: Int): ~~.Flow[A]

Conditionally parallel

Conditionally parallel

Returns ~~.Flow with parallel or sequential implementation, depending on stream having element count equal or greater than given ''threshold''

  (1 <> 50).~.parallelIfOver(100).isParallel   // Returns false

  (1 <> 200).~.parallelIfOver(100).isParallel  // Returns true
Source
_parallel.scala
def parallelWithPriority[A](p: J.Priority, parallelism: Int): ~~.Flow[A]

Parallel with Priority

Parallel with Priority

This is very expensive operation, because it creates a custom thread pool. It only sutable for long running streams

   (1 <> 100).~.parallelWithPriority(MIN, 4).foreach(v => ())

   (1 <> 100).~.parallelWithPriority(MAX).foreach(v => ())

   (1 <> 100).~.parallelWithPriority(J.Priority(5), 4).foreach(v => ())

Note: parallelism determines how many parallel threads are allowed. Default value is CPU core count minus 1

Source
_parallel.scala