Created
May 23, 2013 07:58
-
-
Save walery/5633378 to your computer and use it in GitHub Desktop.
Transform Keys in List of Map in Groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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