-
Notifications
You must be signed in to change notification settings - Fork 0
/
equals.go
52 lines (45 loc) · 873 Bytes
/
equals.go
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
package yamlkeys
func Equals(a any, b any) bool {
switch a_ := a.(type) {
case Map:
if bMap, ok := b.(Map); ok {
// Does A have all the keys that are in B?
for key := range bMap {
if _, ok := MapGet(a_, key); !ok {
return false
}
}
// Are all values in A equal to those in B?
for key, aValue := range a_ {
if bValue, ok := MapGet(bMap, key); ok {
if !Equals(aValue, bValue) {
return false
}
} else {
return false
}
}
return true
} else {
return false
}
case Sequence:
if bList, ok := b.(Sequence); ok {
// Must have same lengths
if len(a_) != len(bList) {
return false
}
for index, aValue := range a_ {
bValue := bList[index]
if !Equals(aValue, bValue) {
return false
}
}
return true
} else {
return false
}
default:
return a == b
}
}