I'd like some sorthand for this:
Map rowToMap(row) {
def rowMap = [:];
row.columns.each{ rowMap[it.name] = it.val }
return rowMap;
}
given the way the GDK stuff is, I'd expect to be able to do something like:
Map rowToMap(row) {
row.columns.collectMap{ [it.name,it.val] }
}
but I haven't seen anything in the docs... am I missing something? or am I just way too lazy?
If what you need is a simple key-value pair, then the method
collectEntries
should suffice. For exampleBut if you want a structure similar to a Multimap, in which there are multiple values per key, then you'd want to use the
groupBy
methodok... I've played with this a little more and I think this is a pretty cool method...
now any subclass of Map or Collection have this method...
here I use it to reverse the key/value in a Map
and here I use it to create a map from a list
now I just pop this into a class that gets called as my app is starting and this method is available throughout my code.
EDIT:
to add the method to all arrays...