I have two maps in Groovy [a: 1, b: 2] and [b:1, c:3] and would like to create from them a third map [a: 1, b: 3, c: 3]. Is there a Gr
[a: 1, b: 2]
[b:1, c:3]
[a: 1, b: 3, c: 3]
I don't think there's a ready-made method for this, maybe use something like:
def m1 = [a: 1, b: 2] def m2 = [b: 1, c: 3] def newMap = (m1.keySet() + m2.keySet()).inject([:]) { acc, k -> acc[k] = (m1[k] ?: 0) + (m2[k] ?: 0); acc }