Skip to content

Instantly share code, notes, and snippets.

@mikhno-s
Created August 1, 2018 22:00
Show Gist options
  • Save mikhno-s/0dd86088849bc301426fc1664517ba15 to your computer and use it in GitHub Desktop.
Save mikhno-s/0dd86088849bc301426fc1664517ba15 to your computer and use it in GitHub Desktop.
This is example of algorithm of merge two lists of maps
public void mergeLists () {
def first = [
["name":"foo","val":"1"],
["name":"bar","val":"2"]
]
def second = [
["name":"foo","val":"666"]
]
def mergedMap = []
first.each { e ->
second.each { e2 ->
if(e.name == e2.name) {
mergedMap.add(["name":e.name, "val":e2.val])
} else {
mergedMap.add(["name":e.name, "val":e.val])
}
}
}
println mergedMap
}
mergeLists()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment