Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create an association with self references
ResourceFunction["AssociationReference"][key] represents a reference to another value in an Association. | |
ResourceFunction["AssociationReference"][<|k1⧴val1,k2⧴val2,…|>] represents an Association where instances of ResourceFunction["AssociationReference"][ki] within the valj are resolved to the values vali. |
Create an AssociationReference object with three keys, two of which reference the other:
In[1]:= | ![]() |
Out[1]= | ![]() |
In[2]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
Many functions work on AssociationReference objects like on Association objects:
In[9]:= | ![]() |
Out[9]= | ![]() |
Part gives values:
In[10]:= | ![]() |
Out[10]= | ![]() |
Key limiting operations return a new AssociationReference object:
In[11]:= | ![]() |
Out[11]= | ![]() |
In[12]:= | ![]() |
Out[12]= | ![]() |
In[13]:= | ![]() |
Out[13]= | ![]() |
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
In[16]:= | ![]() |
Out[16]= | ![]() |
Values and Normal return the final value for each key:
In[17]:= | ![]() |
Out[17]= | ![]() |
In[18]:= | ![]() |
Out[18]= | ![]() |
In[19]:= | ![]() |
Out[19]= | ![]() |
A few basic statistical operations are supported:
In[20]:= | ![]() |
Out[20]= | ![]() |
In[21]:= | ![]() |
Out[21]= | ![]() |
In[22]:= | ![]() |
Out[22]= | ![]() |
Sorting operations return a new AssociationReference object:
In[23]:= | ![]() |
Out[23]= | ![]() |
In[24]:= | ![]() |
Out[24]= | ![]() |
In[25]:= | ![]() |
Out[25]= | ![]() |
Use Map to map a function over values:
In[26]:= | ![]() |
Out[26]= | ![]() |
In[27]:= | ![]() |
Out[27]= | ![]() |
When the value is retrieved, the function is applied on each value:
In[28]:= | ![]() |
Out[28]= | ![]() |
If keys are removed, the resulting AssociationReference object can give values with Missing instead of the dependency:
In[29]:= | ![]() |
Out[29]= | ![]() |
In[30]:= | ![]() |
Out[30]= | ![]() |
Loops are bad:
In[31]:= | ![]() |
Out[31]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License