In groovy, each
(and eachParallel
in GPars) returns the original collection.
What you want is collect
(to return the new collection made by calling the closure)
So, change
strings.eachParallel { it.length() }
to
strings.collectParallel { it.length() }
(btw)
GPars now comes bundled with Groovy so you shouldn't need the @Grab
, and I assume you meant to use your closure
variable in the collect
?
package test
import static groovyx.gpars.GParsPool.withPool
class Test {
List<String> strings = [ "butter", "bread", "dragon", "table" ]
def closure = { it.length() }
def doStuff() {
def results = withPool( 4 ) {
strings.collectParallel closure
}
println results
}
static main( args ) {
def test = new Test()
test.doStuff()
}
}