is an option for functions such as TimeSeries and PersistentSymbol that specifies a function to apply to a list of values.
MergingFunction
is an option for functions such as TimeSeries and PersistentSymbol that specifies a function to apply to a list of values.
Details
- MergingFunction is typically used to process a list of values for cases in which repetition, alternatives or aggregation is possible.
- The merging function takes a list of given values and can return another list or a combination of these values into a single one.
- Some common settings for MergingFunction returning another list include:
-
Identity return the list of all values Flatten return the flattened list of all values Union return the sorted list without duplicates DeleteDuplicates return the original list without duplicates - Some common settings for MergingFunction returning a single value include:
-
First return only the first value Last return only the last value Apply[MissingFallback] return the first value that is not Missing Merge[f] merge associations using the function f - For lists of numeric values, other common settings returning a single value include:
-
Mean return the mean of all values Median return the median of all values Min return the minimum value Max return the maximum value Total return the sum of all values
Examples
open all close allBasic Examples (3)
By default, TimeSeries takes the mean value for duplicate timestamps:
TimeSeries[{1, 2, 3, 4, 5}, {{4.2, 4.2, 5.3, 6.1, 6.1}}]Normal[%]Take the total of the corresponding values:
TimeSeries[{1, 2, 3, 4, 5}, {{4.2, 4.2, 5.3, 6.1, 6.1}}, MergingFunction -> Total]// NormalCreate a number of persistent values with key "pval" at different persistence locations:
PersistentSymbol["pval", "FrontEndSession"] = 1;
PersistentSymbol["pval", "Local"] = 2;Give all values that exist on $PersistencePath:
PersistentSymbol["pval", MergingFunction -> Identity]Give only the first value found:
PersistentSymbol["pval", MergingFunction -> First]Create a number of persistent values with key "lval" at different persistence locations:
PersistentSymbol["lval", "KernelSession"] = {11, 12};
PersistentSymbol["lval", "FrontEndSession"] = {};
PersistentSymbol["lval", "Local"] = {1, {2, 12}};Give the list of all values found:
PersistentSymbol["lval", MergingFunction -> Identity]PersistentSymbol["lval", MergingFunction -> Apply[Join]]PersistentSymbol["lval", MergingFunction -> Flatten]Scope (5)
TimeSeries (1)
By default, TimeSeries takes the mean value for duplicate timestamps:
values = Quantity[{20, 22, 21, 23, 22}, "Millimeters"];times = {Yesterday, Today, Tomorrow, Today, Tomorrow};TimeSeries[values, {times}]Normal[%]Take the maximum of the corresponding values:
TimeSeries[values, {times}, MergingFunction -> Max]// NormalEventSeries (1)
By default, EventSeries stores all time-value pairs, including duplicate times:
values = RandomWord[5]times = RandomDate[Quantity[-3, "Days"], 5, DateGranularity -> "Day"]EventSeries[values, {times}]// NormalTake the first value for each timestamp:
EventSeries[values, {times}, MergingFunction -> First]// NormalGroup values corresponding to the same timestamp:
EventSeries[values, {times}, MergingFunction -> Identity]// NormalPersistentSymbol (3)
Create a complement of persistent values with key "lval" at various locations:
PersistentSymbol["lval", "FrontEndSession"] = {};
PersistentSymbol["lval", "KernelSession"] = {11, 12};
PersistentSymbol["lval", "Local"] = {1, {2, 12}};List all existing values for the key "lval" on $PersistencePath:
PersistentSymbol["lval", MergingFunction -> Identity]By default, only the first value is returned:
PersistentSymbol["lval"]Join and flatten all sublists:
PersistentSymbol["lval", MergingFunction -> Flatten]PersistentSymbol["lval", MergingFunction -> Apply[Join]]Create a complement of persistent associations with name "aval" at various locations:
PersistentSymbol["aval", "FrontEndSession"] = <|"key1" -> 2, "key2" -> {3, 4}|>;
PersistentSymbol["aval", "KernelSession"] = <|"key1" -> 3|>;
PersistentSymbol["aval", "Local"] = <|"key2" -> 2, "key3" -> {8, 9}|>;List all existing values on $PersistencePath:
PersistentSymbol["aval", MergingFunction -> Identity]Merge the values of identical keys in the associations:
PersistentSymbol["aval", MergingFunction -> Merge[Flatten]]Define a default value for "mylist" with a custom merging function:
PersistentSymbol["mylist", "Installation"] = {};io = PersistentObject["mylist", "Installation"]io["MergingFunction"] = Flatten;Define additional values at different persistence locations:
PersistentSymbol["mylist", "Local"] = 3;
PersistentSymbol["mylist", "FrontEndSession"] = {1, 2};For looking up values, the custom merging function is now used:
PersistentSymbol["mylist"]Related Guides
Text
Wolfram Research (2017), MergingFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/MergingFunction.html (updated 2026).
CMS
Wolfram Language. 2017. "MergingFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/MergingFunction.html.
APA
Wolfram Language. (2017). MergingFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MergingFunction.html
BibTeX
@misc{reference.wolfram_2026_mergingfunction, author="Wolfram Research", title="{MergingFunction}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/MergingFunction.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_mergingfunction, organization={Wolfram Research}, title={MergingFunction}, year={2026}, url={https://reference.wolfram.com/language/ref/MergingFunction.html}, note=[Accessed: 12-June-2026]}