Created
December 8, 2014 22:10
-
-
Save csauve/43bf117a31dca9808228 to your computer and use it in GitHub Desktop.
Simple map-reduce in Groovy
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
def mapReduce = { collection, mapper, reducer -> | |
collection.groupBy(mapper) | |
.collectEntries { k, v -> | |
[k, reducer(v)] | |
} | |
} | |
mapReduce([1, 6, 3, 7, 3, 9, 1, 2, 10, 9, 5, 8, 4], | |
{ it % 2 ? "odd" : "even" }, | |
{ it.size }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment