You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
477 B

package genutils
func UpsertIntoArray[T comparable](arr []T, values ...T) []T {
outer:
for _, value := range values {
for _, value2 := range arr {
if value2 == value {
continue outer
}
}
arr = append(arr, value)
}
return arr
}
func RemoveFromArray[T comparable](arr []T, values ...T) []T {
for _, value := range values {
for i, value2 := range arr {
if value2 == value {
arr = append(arr[:i], arr[i+1:]...)
break
}
}
}
return arr
}