({{, (RefLink[MergingFunction, paclet:ref/MergingFunction]) 
is an option for functions such as (RefLink[PersistentValue, paclet:ref/PersistentValue]) that specifies a function to apply to the list of values found.}})

OpenersNotesSection(Spacer1)Details

Some common settings for (RefLink[MergingFunction, paclet:ref/MergingFunction]) include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (5)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a number of persistent values with key "pval" at different persistence locations:

PersistentValue["pval","FrontEndSession"]=1;
PersistentValue["pval","Local"]=2;

Give all values that exist on (RefLink[$PersistencePath, paclet:ref/$PersistencePath]):

PersistentValue["pval",MergingFunction->Identity]

Give only the first value found:

PersistentValue["pval",MergingFunction->First]

Create a number of persistent values with key "lval" at different persistence locations:

PersistentValue["lval","KernelSession"]={11,12};
PersistentValue["lval","FrontEndSession"]={};
PersistentValue["lval","Local"]={1,{2,12}};

Give the list of all values found:

PersistentValue["lval",MergingFunction->Identity]

Join the list values:

PersistentValue["lval",MergingFunction->Apply[Join]]

Flatten all sublists:

PersistentValue["lval",MergingFunction->Flatten]

OpenersExampleSection1(Spacer1)Scope  (3)

Create a complement of persistent values with key "lval" at various locations:

PersistentValue["lval","FrontEndSession"]={};
PersistentValue["lval","KernelSession"]={11,12};
PersistentValue["lval","Local"]={1,{2,12}};

List all existing values for the key "lval" on (RefLink[$PersistencePath, paclet:ref/$PersistencePath]):

PersistentValue["lval",MergingFunction->Identity]

By default, only the first value is returned:

PersistentValue["lval"]

Join and flatten all sublists:

PersistentValue["lval",MergingFunction->Flatten]

Join all sublists:

PersistentValue["lval",MergingFunction->Apply[Join]]

Create a complement of persistent associations with name "aval" at various locations:

PersistentValue["aval","FrontEndSession"]=<|"key1"->2,"key2"->{3,4}|>;
PersistentValue["aval","KernelSession"]=<|"key1"->3|>;
PersistentValue["aval","Local"]=<|"key2"->2,"key3"->{8,9}|>;

List all existing values on (RefLink[$PersistencePath, paclet:ref/$PersistencePath]):

PersistentValue["aval",MergingFunction->Identity]

Merge the values of identical keys in the associations:

PersistentValue["aval",MergingFunction->Merge[Flatten]]

Define a default value for "mylist" with a custom merging function:

PersistentValue["mylist","Installation",MergingFunction->Flatten]={};

Define additional values at different persistence locations:

PersistentValue["mylist","Local"]=3;
PersistentValue["mylist","FrontEndSession"]={1,2};

For looking up values, the custom merging function is now used:

PersistentValue["mylist"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[PersistentValue, paclet:ref/PersistentValue])  ▪  (RefLink[$PersistencePath, paclet:ref/$PersistencePath])  ▪  (RefLink[KeyCollisionFunction, paclet:ref/KeyCollisionFunction])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Setting Persistent Values, paclet:guide/SettingPersistentValues])}})}})