diff --git a/misc.go b/misc.go index 0674718..5b89537 100644 --- a/misc.go +++ b/misc.go @@ -1,6 +1,7 @@ package main import ( + "slices" "unicode" ) @@ -13,3 +14,14 @@ func assert(cond bool) { panic("Assertion Failed") } } + +// Ensure that the given elements are only appended to the given slice if they +// don't already exist. +func unique_append[T comparable](slc []T, items ...T) []T { + for _, item := range items { + if !slices.Contains(slc, item) { + slc = append(slc, item) + } + } + return slc +}