-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathmerge.cue
101 lines (98 loc) · 1.68 KB
/
merge.cue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package metadata
remap: functions: merge: {
category: "Object"
description: """
Merges the `from` object into the `to` object.
"""
arguments: [
{
name: "to"
description: "The object to merge into."
required: true
type: ["string"]
},
{
name: "from"
description: "The object to merge from."
required: true
type: ["object"]
},
{
name: "deep"
description: "If true a deep merge is performed, otherwise only top level fields are merged."
required: false
default: false
type: ["boolean"]
},
]
internal_failure_reasons: []
return: {
types: ["object"]
rules: [
#"If a key exists in both objects, the field from the `from` object is chosen."#,
#"If `deep` is specified, and a key exists in both objects, and both these fields are also objects, then those objects will merge recursively as well."#,
]
}
examples: [
{
title: "Object merge (shallow)"
source: #"""
merge(
{
"parent1": {
"child1": 1,
"child2": 2
},
"parent2": {
"child3": 3
}
},
{
"parent1": {
"child2": 4,
"child5": 4
}
}
)
"""#
return: {
parent1: {
child2: 4
child5: 5
}
parent2: child3: 3
}
},
{
title: "Object merge (deep)"
source: #"""
merge(
{
"parent1": {
"child1": 1,
"child2": 2
},
"parent2": {
"child3": 3
}
},
{
"parent1": {
"child2": 4,
"child5": 4
}
},
deep: true
)
"""#
return: {
parent1: {
child1: 1
child2: 4
child5: 5
}
parent2: child3: 3
}
},
]
}