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
This does it:
Map additionJoin( Map map1, Map map2 )
{
def result = [:];
result.putAll( map1 );
result.putAll( map2 );
result.each { key, value ->
if( map1[key] && map2[key] )
{
result[key] = map1[key] + map2[key]
}
}
return result;
}
def a = [a: 1, b: 2]
def b = [b:1,c:3]
def c = additionJoin( a, b )
println c