Created
August 21, 2010 18:54
-
-
Save xlson/542696 to your computer and use it in GitHub Desktop.
Example of using groupBy and collect together
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
// Example of using groupBy and collect together | |
def values = | |
[[lastname: "Anderson", age: 30], | |
[lastname: 'Bergstrom', age: 24], | |
[lastname: 'Anderson', age: 45], | |
[lastname: 'Bergstrom', age: 40], | |
[lastname: 'Brown', age: 25]] | |
// Find average age by lastname: | |
values.groupBy { it.lastname } | |
.collect { key, value -> ["$key": value.age.sum()/value.size()] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment