({{, (RefLink[ValuePreprocessingFunction, paclet:ref/ValuePreprocessingFunction]) 
is an option for functions such as (RefLink[PersistentValue, paclet:ref/PersistentValue]) and (RefLink[InitializationValue, paclet:ref/InitializationValue]) that specifies a function to apply to a new value that is being assigned.}})

OpenersNotesSection(Spacer1)Details

When a value is to be assigned with (RefLink[PersistentValue, paclet:ref/PersistentValue])["name",…]=value or (RefLink[InitializationValue, paclet:ref/InitializationValue])["name",…]=value, the setting of the (RefLink[ValuePreprocessingFunction, paclet:ref/ValuePreprocessingFunction]) option is applied to value; the result is then assigned. If the result is (RefLink[$Failed, paclet:ref/$Failed]), no assignment is done.

The default setting is (RefLink[ValuePreprocessingFunction, paclet:ref/ValuePreprocessingFunction])->(RefLink[Identity, paclet:ref/Identity]), which does not modify the value to be assigned.

Settings for (RefLink[ValuePreprocessingFunction, paclet:ref/ValuePreprocessingFunction]) are typically done for the "Installation" persistence location.

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Define a value preprocessing function that accepts only integers:

validateInteger[x_]:=If[IntegerQ[x],x,$Failed]

Set up a default value and the value preprocessing function for a persistent value named "int":

PersistentValue["int","Installation",ValuePreprocessingFunction->validateInteger]=0;

Assign an integer at any persistence location:

PersistentValue["int","KernelSession"]=42;

Assigning anything else generates an error, and the assignment is not performed:

PersistentValue["int","KernelSession"]=0.5;

PersistentValue["int"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[PersistentValue, paclet:ref/PersistentValue])  ▪  (RefLink[PersistenceLocation, paclet:ref/PersistenceLocation])  ▪  (RefLink[Protected, paclet:ref/Protected])}})}})