Skip to content

Instantly share code, notes, and snippets.

@xlson
Created August 21, 2010 18:54
Show Gist options
  • Save xlson/542696 to your computer and use it in GitHub Desktop.
Save xlson/542696 to your computer and use it in GitHub Desktop.
Example of using groupBy and collect together
// 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