Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
@Grab('org.codehaus.gpars:gpars:0.11-beta-3')
import static groovyx.gpars.GParsPool.withPool

THRESHHOLD = 10

def partition(piece) {
  piece.size() <= THRESHHOLD ? piece :
    [piece[0..<THRESHHOLD]] + partition(piece.substring(THRESHHOLD))
}

def pwords = { input ->
  withPool(THREADS) {
    partition(input).parallel.map(swords).reduce{ a, b -> a + b }.flatten()
  }
}

...