title: “MAP::EXTEND Function” author: “Pierre Laplante laplante@plcb.ca” date: “2023-11-19” version: “1.0.0”
map::extend merges two or more maps and returns a new map.
map::extend or extend(map[, map..., deep: bool])
The map::extend function merges two or more maps and returns a new map.
If the parameter deep is set to true, the merge is recursive, meaning nested maps will also be merged instead of replaced.
If deep is not specified, only the top-level keys will be merged.
res={{
option := {"selection": "#main_page"};
option2 := {"data": {"uuid": "1234-2345-rert"} };
option3 := {"data": {"uids": ["123", "234", "345"]} };
option4 := {"data": {"targets": [{"primary": "test"}, {"primary": "test2"}]} };
option = extend(option, option2, option3, option4, deep: true);
option;
}}.
return
res={"data":{"targets":[{"primary":"test"},{"primary":"test2"}],"uids":["123","234","345"],"uuid":"1234-2345-rert"},"selection":"#main_page"}.
res={{
option := {"selection": "#main_page"};
option2 := {"data": {"uuid": "1234-2345-rert"}, "target": "blank"};
option3 := {"data": {"page": 1} };
option = extend(option, option2, option3);
option;
}}.
return
res={"data":{"page":1},"selection":"#main_page","target":"blank"}.
res={{
option := {"data": {"uuid": "1234-2345-rert"} };
option2 := {"data": {"page": "1"} };
option = extend(option, option2, deep: true);
option;
}}.
return
res={"data":{"page":"1","uuid":"1234-2345-rert"}}.
res={{
option := {"data": {"uuid": "1234-2345-rert"} };
option2 := {"data": {"page": "1"} };
option = extend(option, option2);
option;
}}.
return
res={"data":{"page":"1"}}.
res={{
option := {"selection": "#main_page"};
option2 := {"selection": "#sub_page", "data": {"uuid": "1234-2345-rert"} };
option = extend(option, option2);
option;
}}.
return
res={"data":{"uuid":"1234-2345-rert"},"selection":"#sub_page"}.
res={{
option := {"selection": "#main_page"};
option2 := {
"data": {
"uuid": "1234-2345-rert"
}
};
option = extend(option, option2);
option;
}}.
return
res={"data":{"uuid":"1234-2345-rert"},"selection":"#main_page"}.
res={{
option := {"selection": "#main_page"};
option2 := {"selection": "#sub_page"};
option = extend(option, option2);
option;
}}.
return
res={"selection":"#sub_page"}.
res={{
extend({}, { "x" : 1 });
extend({"x" : true}, { "x" : 1 });
a := extend({"x" : true}, { "y" : 1 });
a;
}}.
return
res={"x":1}{"x":1}{"x":true,"y":1}.
Pierre Laplante laplante@plcb.ca