Skip to content

Instantly share code, notes, and snippets.

@hgmiguel
Created July 27, 2014 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgmiguel/e847aac977b6bd2b1e59 to your computer and use it in GitHub Desktop.
Save hgmiguel/e847aac977b6bd2b1e59 to your computer and use it in GitHub Desktop.
Collection Pipeline in groovy
some_articles
.collectMany{article -> article.tags.collect{ [ ( it ), article] }}
.groupBy{it.first()}
.collectEntries {k,v -> [( k ): v.collect {it.last()}]}
.collect {k,v -> [( k ):[articles: v.size(),words:v.collect{it.words}.inject(0) { acc, val -> acc + val }] ]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment