Skip to content

Instantly share code, notes, and snippets.

@walery
Created May 23, 2013 07:58
Show Gist options
  • Select an option

  • Save walery/5633378 to your computer and use it in GitHub Desktop.

Select an option

Save walery/5633378 to your computer and use it in GitHub Desktop.
Transform Keys in List of Map in Groovy
def listOfMap = [[a:"alpha", b:"beta", c:"chrome"],[a:"uno", b:"due",c:"drei"]]
def ti = [a:"AKAY", c:"ccc", d:"dd"]
List<Map> transformKeys(List<Map> lom, Map trans) {
lom.collect{ map ->
map.collectEntries{ entry ->
trans.containsKey(entry.key) ? [(trans.get(entry.key)):entry.value] : entry
}
}
}
transformKeys(listOfMap, ti)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment