Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.8.1, 1.9-beta-1
-
Component/s: groovy-jdk
-
Labels:None
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
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.
Activity
Guillaume Laforge
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Assignee | Guillaume Laforge [ guillaume ] |
Guillaume Laforge
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 1.8.1 [ 17223 ] | |
| Fix Version/s | 1.9-beta-1 [ 17153 ] | |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |