Created
September 6, 2010 11:52
-
-
Save thevery/566942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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