go-nostr/sdk/helpers.go

22 lines
410 B
Go
Raw Permalink Normal View History

package sdk
2024-10-06 15:53:33 -03:00
import (
"slices"
jsoniter "github.com/json-iterator/go"
2024-10-06 15:53:33 -03:00
)
var json = jsoniter.ConfigFastest
2025-03-04 11:08:31 -03:00
// appendUnique adds items to an array only if they don't already exist in the array.
// Returns the modified array.
2024-10-06 15:53:33 -03:00
func appendUnique[I comparable](arr []I, item ...I) []I {
for _, item := range item {
if slices.Contains(arr, item) {
return arr
}
arr = append(arr, item)
}
return arr
}