Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
Patch
Description
As described in a thread in the groovy user list here:
http://groovy.329449.n5.nabble.com/a-possibly-useful-collection-method-tp4428105p4428105.html
An implementation of groupBy that receives a list or an array of closures as criteria for grouping would be useful for making nested groupings.
def grouped = [ [aa: 11, bb: 22, cc: 33], [aa: 22, bb: 22, cc: 44], [aa: 11, bb: 22, cc: 55], [aa: 22, bb: 33, cc: 66], [aa: 33, bb: 44, cc: 77] ].groupBy({ it.aa }, { it.bb }) def expected = [ 11:[22:[[aa:11, bb:22, cc:33], [aa:11, bb:22, cc:55]]], 22:[22:[[aa:22, bb:22, cc:44]], 33:[[aa:22, bb:33, cc:66]]], 33:[44:[[aa:33, bb:44, cc:77]]] ] assert grouped[11][22] == [[aa:11, bb:22, cc:33], [aa:11, bb:22, cc:55]] assert grouped[22][33] == [[aa:22, bb:33, cc:66]] assert grouped[11][99] == null
groupBy with one closure criterion would behave like the current implementation of groupBy.