Open danhyun opened 10 years ago
Thanks for the feedback. The closure doesn't have to return a map, but if not, it must be a list. So an alternative fix is:
def tagcloudMap = tagList.collectEntries { pair -> pair as List }
Groovy normally allows you to use arrays and lists interchangeably, but not in this case.
@pledbrook thanks for the quick response. It's very satisfying to see that there is a groovier solution than
[ (it[0]) : it[1] ]
I should really start working through the Groovy in Action MEAP.
I am using grails 2.3.4 and working my way through the v13 of book.
I came across the wonderful demonstration of
withCriteria
andprojections
.In this snippet:
tagList
is an array of arrays. When building thetagcloudMap
, the code is listed as:However, this results in a run-time exception:
I did some research as I am a groovy novice and it appears that
collectEntries
needs to have a map returned from the closure. Because the entries intagList
are arrays and not maps, I think this is causing the run-time exception.I have tried this:
And it appears to be in working order: