Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Merge a list of nested associations
ResourceFunction["MergeNested"][{assoc1,assoc2,…},f] merges a list of nested associations recursively. | |
ResourceFunction["MergeNested"][f] represents an operator form of ResourceFunction["MergeNested"] that can be applied to an expression. |
Merge two nested associations of the same depth. The returned association will have all of the keys of the original two:
In[1]:= |
Out[1]= |
Use the operator form instead:
In[2]:= |
Out[2]= |
Merge different types of key-value data:
In[3]:= |
Out[3]= |
Merging with Last returns an association where the values of keys are taken from the rightmost association where that value is defined. This essentially mimics a hierarchical inheritance structure:
In[4]:= |
Out[4]= |
Merging an empty list returns the empty association:
In[5]:= |
Out[5]= |
For simple associations and other key-value data, MergeNested is identical to Merge:
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
In[8]:= |
Out[8]= |
When merging associations of different depths, the merging stops as soon as the depth of the shallowest association is reached:
In[9]:= |
Out[9]= |
This work is licensed under a Creative Commons Attribution 4.0 International License