First map is default options [a: true, b: false]
. Second map - options passed by user [a:false]
. Does Groovy has maps merge method to obtain [a: false, b:false]
?
It's not problem to implement it in Groovy. I'm asking about method out of the box
2. The each Method. In Groovy, maps created with the literal notation are ordered.
concat() Alternatively, we can use Stream#concat() function to merge the maps together. This function can combine two different streams into one. As shown in the snippet, we are passed the streams of map1 and map2 to the concate() function and then collected the stream of their combined entry elements.
You can use plus:
assert [ a: true, b: false ] + [ a: false ] == [ a: false, b: false ]
Or left shift:
assert [ a: true, b: false ] << [ a: false ] == [ a: false, b: false ]
The difference is that <<
adds the right hand map into the left hand map. When you use +
, it constructs a new Map based on the LHS, and adds the right hand map into it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With