Repository navigation
Conversation
Merge overwrites slices wholesale, so anyone who wants layered config to add to a list instead of replacing it has to write a WithMergeFunc from scratch and reimplement the deep merge around it. This adds three ready made strategies in the maps package and exposes each one as a Load option. MergeAppendSlices concatenates the source slice after the destination one. MergeByIndex pairs elements at the same index, deep merging maps and recursing into nested slices. MergeByKey matches map elements on a named field, deep merging the ones that match and appending the ones that do not, with the first destination element winning when a field value repeats. All three keep the existing behaviour for nested maps and non slice values, and handle concrete slice types such as []string rather than only []any. Values taken from the source are deep copied, so mutating the source after a merge cannot reach into the merged result. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mergeoverwrites slices wholesale, so anyone who wants a later config layer to addto a list rather than replace it has to write a
WithMergeFuncfrom scratch andreimplement the deep merge around it. This adds three ready-made strategies to the
mapspackage and exposes each one as aLoadoption.MergeAppendSlicesconcatenates the source slice after the destination one.MergeByIndexpairs elements at the same index, deep-merging maps and recursinginto nested slices.
MergeByKey(field)matches map elements on a named field, deep-merging the onesthat match and appending the ones that do not. When a field value repeats on the
destination side, the first element wins. An empty field name returns an error.
All three keep the existing behaviour for nested maps and non-slice values, and they
handle concrete slice types such as
[]stringrather than only[]any. Values takenfrom the source are deep-copied, so mutating the source after a merge cannot reach
into the merged result.
WithMergeAppendSlices(),WithMergeByIndex()andWithMergeByKey(field)wire theseinto
Load. Tests cover both themapsfunctions directly and theLoadoptionsend to end.
One note on module ordering: the
Loadoptions live in the root module but call intothe
mapsmodule, which the workspace resolves locally. Releasing the root modulewould need a
mapstag first. Happy to split this into amaps-only PR and afollow-up for the
Loadoptions if you'd prefer that sequencing.