Skip to content

Instantly share code, notes, and snippets.

@thevery
Created September 6, 2010 11:52
Show Gist options
  • Save thevery/566942 to your computer and use it in GitHub Desktop.
Save thevery/566942 to your computer and use it in GitHub Desktop.
import static groovyx.gpars.GParsPool.withPool
def words = "This is just a plain text to count words in".tokenize()
print count(words)
def count(arg) {
withPool {
return arg.parallel
.map{[it, 1]}//probably implicit new MapEntry(it, 1) is better
// .groupBy{it[0]} - this should be implicit
.reduce {value1, value2 -> value1+value2}
.collection
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment