diff options
Diffstat (limited to 'compare/compare.go')
-rw-r--r-- | compare/compare.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compare/compare.go b/compare/compare.go index de97690c7..67bb1c125 100644 --- a/compare/compare.go +++ b/compare/compare.go @@ -36,3 +36,19 @@ type ProbablyEqer interface { type Comparer interface { Compare(other any) int } + +// Eq returns whether v1 is equal to v2. +// It will use the Eqer interface if implemented, which +// defines equals when two value are interchangeable +// in the Hugo templates. +func Eq(v1, v2 any) bool { + if v1 == nil || v2 == nil { + return v1 == v2 + } + + if eqer, ok := v1.(Eqer); ok { + return eqer.Eq(v2) + } + + return v1 == v2 +} |