I have a list as below
def qresultList = [
[location: 'a', txs: 10],
[location: 'b', txs: 20],
[location: 'a', txs: 30]
]
I want to get distinct list of locations with sum of txs for same location.. so I am doing groupby on location like this:
def totalsByLocation1 = qresultList.groupBy{ it.location }.
collectEntries{ key, vals -> [key, vals*.txs.sum()] }
The above code is inside SummaryUtilsService/getWorldSummary function
I am getting the following error
No signature of method: java.util.LinkedHashMap.collectEntries() is applicable for argument types: (summary.SummaryUtilsService$_getWorldSummary_closure3) values: [summary.SummaryUtilsService$_getWorldSummary_closure3@2750e6c9]
Update: the actual result from the query is
def qresultList = [
['a', 10],
['b', 20],
['a', 30]
]
so Its a list of lists..
From earlier questions, I assume you’re using Grails 1.3.7 or something
The pre-groovy 1.8.X way of doing this is:
Edit
If your input list is:
Then you will need something like: