fix AppendUnique.

This commit is contained in:
fiatjaf
2026-04-02 03:22:47 -03:00
parent 2c30300756
commit 72a5be58d7
+9 -7
View File
@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"cmp" "cmp"
"net/url" "net/url"
"slices"
"unsafe" "unsafe"
"github.com/templexxx/xhex" "github.com/templexxx/xhex"
@@ -89,14 +88,17 @@ func CompareRelayEventReverse(b, a RelayEvent) int {
// AppendUnique adds items to an array only if they don't already exist in the array. // AppendUnique adds items to an array only if they don't already exist in the array.
// Returns the modified array. // Returns the modified array.
func AppendUnique[I comparable](arr []I, item ...I) []I { func AppendUnique[I comparable](list []I, newEls ...I) []I {
for _, item := range item { ex:
if slices.Contains(arr, item) { for _, newEl := range newEls {
return arr for _, el := range list {
if el == newEl {
continue ex
}
} }
arr = append(arr, item) list = append(list, newEl)
} }
return arr return list
} }
func IsOlder(previous, next Event) bool { func IsOlder(previous, next Event) bool {