Created
May 24, 2012 00:45
-
-
Save mike-neck/2778647 to your computer and use it in GitHub Desktop.
副作用のない並行プログラミング
This file contains hidden or 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(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