Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Created May 24, 2012 00:45
Show Gist options
  • Select an option

  • Save mike-neck/2778647 to your computer and use it in GitHub Desktop.

Select an option

Save mike-neck/2778647 to your computer and use it in GitHub Desktop.
副作用のない並行プログラミング
import static groovyx.gpars.GParsPool.*
withPool(3) {
(1..20).parallel.map {
[
duo : it % 2 == 0? 1 : 0,
tri : it % 3 == 0? 1 : 0,
cinq : it % 5 == 0? 1 : 0
]
}.reduce { a, b ->
def map = [:]
a.each {k, v ->
map[k] = v + b[k]
}
map
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment