From cd680371fb7b99aadd0c12b1db6f23f231079083 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 28 Oct 2024 17:31:21 -0400 Subject: [PATCH] Added function allEqual - checks if all given values are equal --- misc.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/misc.go b/misc.go index cf56708..8f4f904 100644 --- a/misc.go +++ b/misc.go @@ -27,3 +27,14 @@ func unique_append[T comparable](slc []T, items ...T) ([]T, int) { } return slc, num_appended } + +// Returns true only if all the given elements are equal +func allEqual[T comparable](items ...T) bool { + first := items[0] + for _, item := range items { + if item != first { + return false + } + } + return true +}