英文:
Example of merge operation in helm
问题
在官方文档中,描述非常简略:
> 将两个或多个字典合并成一个,以目标字典为优先:
>
> $newdict := merge $dest $source1 $source2 这是深度合并操作,而不是深度复制操作。被合并的嵌套对象在两个字典中是同一实例。如果您需要深度复制以及合并,请使用deepCopy函数与合并...
您是否需要示例输入和输出数值?
英文:
In offcial documentaion the description is very poor:
> Merge two or more dictionaries into one, giving precedence to the dest
> dictionary:
>
> $newdict := merge $dest $source1 $source2 This is a deep merge
> operation but not a deep copy operation. Nested objects that are
> merged are the same instance on both dicts. If you want a deep copy
> along with the merge, then use the deepCopy function along with
> merging...
Could you please provide example with input and output values ?
答案1
得分: 3
以下是您要翻译的内容:
合并
在合并字典时,具有不同值的键将被保留,对于相同键的情况,dst
字典具有优先权。例如,merge $dst $src1 $src2
的结果将是:
或者在helm语法中:
{{ $mergedDict := merge $dst $src1 $src2 }}
将会是:
mergedDict: map[default:default key:true name:value1 overwrite:me]
mergeOverwrite
在mergeOverwrite中,优先顺序是从右到左。所以我们有:
{{ $mergedDict := mergeOverwrite $dst $src1 $src2}}
将会是:
mergedDict: map[default:default key:false name:value2 overwrite:overwritten]
或
{
"default": "default",
"key": "false",
"name": "value2",
"overwrite": "overwritten"
}
英文:
Consider we have 3 maps (or Dict) as follows:
dst = {
"default": "default",
"overwrite": "me",
"key": "true"
}
src1 = {
"overwrite": "overwritten",
"key": "false",
"name": "value1"
}
src2 = {
"key": "false",
"name": "value2"
}
You can represent it in helm with:
{{ $dst := dict "default" "default" "overwrite" "me" "key" "true"}}
{{ $src1 := dict "overwrite" "overwritten" "key" "false" "name" "value1"}}
{{ $src2 := dict "key" "false" "name" "value2"}}
Merge
In merging dicts, keys with different values will be kept, and in the same keys cases, dst
dict takes precedence.
For example, result of merge $dst $src1 $src2
would be:
mergedDict = {
"default": "default",
"key": "true",
"name": "value1",
"overwrite": "me"
}
or in helm syntacs:
{{ $mergedDict := merge $dst $src1 $src2 }}
would be:
mergedDict: map[default:default key:true name:value1 overwrite:me]
mergeOverwrite
In mergeOverwrite, precedence would be from right to left. So we have:
{{ $mergedDict := mergeOverwrite $dst $src1 $src2}}
would be:
mergedDict: map[default:default key:false name:value2 overwrite:overwritten]
or
{
"default": "default",
"key": "false",
"name": "value2",
"overwrite": "overwritten"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论