Function Repository Resource:

# ConstantAssociation

Create an association whose values are all a constant

Contributed by: Seth J. Chandler
 ResourceFunction["ConstantAssociation"][keys,value] creates an Association whose keys are keys and whose values are all value. ResourceFunction["ConstantAssociation"][value] is an operator form of ResourceFunction["ConstantAssociation"].

## Details and Options

ResourceFunction["ConstantAssociation"] is a more expressive form of AssociationThread in which the second argument is the constant value. It also has an operator form.
This function is identical to a function found in the "GeneralUtilities`" context, except that it adds an operator form.
Generally, keys should be a List.

## Examples

### Basic Examples (3)

Create an association with two keys and whose values are all 0:

 In[1]:=
 Out[1]=

Create an association whose values are all Missing[]:

 In[2]:=
 Out[2]=

The operator form of ConstantAssociation:

 In[3]:=
 In[4]:=
 Out[4]=

### Scope (1)

The constant value can be any Wolfram Language expression:

 In[5]:=
 Out[5]=

### Applications (4)

Use the resource function JoinRest with ConstantAssociation to create default values for an Association that is missing certain key-value pairs:

 In[6]:=
 Out[6]=

Use the resource function JoinMost with ConstantAssociation to override values for certain keys in an association:

 In[7]:=
 Out[7]=

Store and use an operator that will assign Missing[] as the value to a list of keys:

 In[8]:=
 In[9]:=
 Out[9]=

Use ConstantAssociation in conjunction with the resource function JoinRest to convert a ragged list of associations into a regular one:

 In[10]:=
 Out[10]=

### Neat Examples (1)

Tally the frequency of the characters "a" through "j" in a list that is missing many of those characters:

 In[11]:=
 Out[11]=

Seth J. Chandler

## Version History

• 1.0.0 – 26 July 2019