You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, we are heavily depends on terraform and we using provider named cloudposse/terraform-provider-utils their code based on mergo to provide merge capabilities of complex structures. We noticed a issue while structures which can have slices and as for us this behavior far from correct ( maybe this is a feature :) ).
Use case:
We have 2 inputs as yaml which are decoded into terraform structures.
NOTE: in some cases it may happen that we can have dups inside arrays
NOTE: order preserved, sort not used to ensure merged lists preserving the same or close to original order.
WithSliceDeepCopy from my understanding supposed to copy items from both slices and merge them together, but this not happening and only Config A is seems copied. I'm not fully sure is that a goal for WithSliceDeepCopy or not?
In a same time WithAppendSlice almost meet our expectations, but as you can see above from result for it, we have duplicates, because both Configs include value-1.
It can be easily fixed by de-duplication of final slice, but current way of WithAppendSlice probably desired result for some cases.
Before to do any PRs i would like to ask if we can add to version 1 of mergo a modifier like WithSliceDeduplication which then can call extra logic within WithAppendSlice scope ?
I did locally such functionality and its behavior looks good, plus using options approach we can preserve existing behavior, while with WithSliceDeduplication we can extend it without breaking anyones experience who already using `mergo.
The text was updated successfully, but these errors were encountered:
I can see this is PR and feature for v2 in /pull/196 , but last message from 2023 and no movements about v2 since then, but deduplication feature is the one of very important part we missing with mergo
Hi all, we are heavily depends on terraform and we using provider named
cloudposse/terraform-provider-utils
their code based onmergo
to provide merge capabilities of complex structures. We noticed a issue while structures which can have slices and as for us this behavior far from correct ( maybe this is a feature :) ).Use case:
We have 2 inputs as yaml which are decoded into terraform structures.
Config A
Config B
Results if we using
WithAppendSlice
Results if we using
WithSliceDeepCopy
Result with
WithAppendSlice
andWithSliceDeduplication
WithSliceDeepCopy
from my understanding supposed to copy items from both slices and merge them together, but this not happening and only Config A is seems copied. I'm not fully sure is that a goal forWithSliceDeepCopy
or not?In a same time
WithAppendSlice
almost meet our expectations, but as you can see above from result for it, we have duplicates, because both Configs includevalue-1
.It can be easily fixed by de-duplication of final slice, but current way of
WithAppendSlice
probably desired result for some cases.Before to do any PRs i would like to ask if we can add to version 1 of
mergo
a modifier likeWithSliceDeduplication
which then can call extra logic withinWithAppendSlice
scope ?All we need add extra helper function and condition to enable this function to end of this block: https://github.com/darccio/mergo/blob/master/merge.go#L171-L175
I did locally such functionality and its behavior looks good, plus using options approach we can preserve existing behavior, while with
WithSliceDeduplication
we can extend it without breaking anyones experience who already using `mergo.The text was updated successfully, but these errors were encountered: