If I have a rule
oldRule = {a -> 1, b -> 2}
{a->1,b->2}
Then I have a new rule newRule = {a -> 8, c -> 2}
.How to use it to update my oldRule
?I hope to get
{a->8,b->2,c->2}
Actually I think the Union
can implement this target.But it always will choice that small element.I don't know how to control this behavior.
Union[{a -> 8, c -> 2}, oldRule, SameTest -> (SameQ @@ Keys[{##}] &)]
{a -> 1, b -> 2, c -> 2}
Or any elegant workaround can do this?
<|a -> 1, b -> 2, c -> 2|>
?It's allowed. $\endgroup$Join[oldRule, newRule]
works. $\endgroup$