Merging two %Objects (2016.1/2016.2)
Discussion (1)1
Comments
Hi Tim,
$compose works with deep structures but it replaces values of key-value pairs at the top level. It does not merge sub-arrays or sub-objects by default. Consider the following code:
SAMPLES>set o1 = {"a":1,"c":2,"deep":{"f":1,"g":1}}
SAMPLES>set o2 = {"b":1,"c":1,"deep":{"f":3,"j":1}}
SAMPLES>s o3 = o2.$compose({"returnValue":o1})
SAMPLES>w o3.$toJSON()
{"a":1,"c":1,"deep":{"f":3,"j":1},"b":1You can easily spot, that the path "deep" in o3 has the value from o2 and completely misses "deep.g" from o1. We just copied the path "deep" from o2 into o1. We do provide a way to override this behavior if you want to, but in a future release, we plan to ease this by introducing compose maps. I will cover this topic in more detail in an upcoming post.