-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathequal.go
37 lines (32 loc) · 900 Bytes
/
equal.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
package any
import "reflect"
// Equaler provides a way to let an underlying value define equality for Value.
type Equaler interface {
// Equal determines if a Value is equal to another Value.
Equal(Value) bool
}
// Equal satisfies Equaler for Value.
// Equality will be determined by the underlying values when Equaler is satisfied by either value.
// Otherwise, equality is determined by reflect.DeepEqual on the underlying values.
func (v Value) Equal(other Value) bool {
if eq, ok := v.i.(Equaler); ok {
return eq.Equal(other)
}
if eq, ok := other.i.(Equaler); ok {
return eq.Equal(v)
}
return reflect.DeepEqual(v.i, other.i)
}
var _ Equaler = (*Value)(nil)
// Equal determines if a Map is equal to another Map.
func (m Map) Equal(other Map) bool {
if len(m) != len(other) {
return false
}
for k, v := range m {
if !v.Equal(other[k]) {
return false
}
}
return true
}