diff options
Diffstat (limited to 'vendor/codeberg.org/gruf/go-cache/v2/compare.go')
-rw-r--r-- | vendor/codeberg.org/gruf/go-cache/v2/compare.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-cache/v2/compare.go b/vendor/codeberg.org/gruf/go-cache/v2/compare.go new file mode 100644 index 000000000..749d6c05f --- /dev/null +++ b/vendor/codeberg.org/gruf/go-cache/v2/compare.go @@ -0,0 +1,23 @@ +package cache + +import ( + "reflect" +) + +type Comparable interface { + Equal(any) bool +} + +// Compare returns whether 2 values are equal using the Comparable +// interface, or failing that falls back to use reflect.DeepEqual(). +func Compare(i1, i2 any) bool { + c1, ok1 := i1.(Comparable) + if ok1 { + return c1.Equal(i2) + } + c2, ok2 := i2.(Comparable) + if ok2 { + return c2.Equal(i1) + } + return reflect.DeepEqual(i1, i2) +} |