Proton v0.1.0 Proton.Merger

Functions for merging spec data (which are maps) intelligently.

Link to this section Summary

Functions

Merge spec structures intelligently. Strategy: In the cases where the old and new versions are maps, either replace the old one outright if the clobber option is set, or recursively call self on the old and new maps if not; in the cases where the old and new versions are both lists, either replace the old one outright if the clobber option is set, or append the incoming values to the existing list. In any other case—-including cases where the value was unset, cases where the two values differ in type, or cases where both values are scalars—-the old value is overwritten

Link to this section Functions

Link to this function smart_merge(left, right)

Merge spec structures intelligently. Strategy: In the cases where the old and new versions are maps, either replace the old one outright if the clobber option is set, or recursively call self on the old and new maps if not; in the cases where the old and new versions are both lists, either replace the old one outright if the clobber option is set, or append the incoming values to the existing list. In any other case—-including cases where the value was unset, cases where the two values differ in type, or cases where both values are scalars—-the old value is overwritten.

The “clobber option”: If the first element of a list is the atom :_clobber!, or if that atom keys a truth-y value in a map, then the option is set. Not sure how I feel about this sort of in-band configuration in general, but in this case it seems like the best solution, as it lets you specify that behavior (or not) on any complex type, at any level of nested mapping.