Files
netbird-kubernetes-operator/internal/util/slices.go
T
Philip LaineandGitHub 47b1f55c45 Set Go toolchain to v1.26.1 and apply modernizations (#138)
This change makes sure that we use the latest Go version when building
and applies some modernization fixes.
2026-03-12 21:40:36 +01:00

47 lines
799 B
Go

package util
import "strings"
// Without return all of x in same order without y
func Without[T comparable](x []T, y T) []T {
var ret []T
for _, v := range x {
if v != y {
ret = append(ret, v)
}
}
return ret
}
// Equivalent return true if x and y are equal when sorted
func Equivalent[T comparable](x, y []T) bool {
if len(x) != len(y) {
return false
}
mp := make(map[T]any)
for _, v := range x {
mp[v] = nil
}
for _, v := range y {
if _, ok := mp[v]; !ok {
return false
}
}
return true
}
// SplitTrim split string and trim whitespace
func SplitTrim(str, sep string) []string {
if len(str) == 0 {
return nil
}
sp := strings.Split(str, sep)
ret := make([]string, 0, len(sp))
for _, v := range sp {
ret = append(ret, strings.TrimSpace(v))
}
return ret
}