This commit is contained in:
2023-07-19 19:24:58 +02:00
parent 56684b2c0b
commit 1ee127937a
5 changed files with 177 additions and 17 deletions

View File

@@ -290,3 +290,14 @@ func ArrRemove[T comparable](arr []T, needle T) []T {
}
return arr
}
func ArrExcept[T comparable](arr []T, needles ...T) []T {
r := make([]T, 0, len(arr))
rmlist := ArrToSet(needles)
for _, v := range arr {
if _, ok := rmlist[v]; !ok {
r = append(r, v)
}
}
return r
}

View File

@@ -29,6 +29,14 @@ func ArrToMap[T comparable, V any](a []V, keyfunc func(V) T) map[T]V {
return result
}
func ArrToSet[T comparable](a []T) map[T]bool {
result := make(map[T]bool, len(a))
for _, v := range a {
result[v] = true
}
return result
}
func MapToArr[T comparable, V any](v map[T]V) []MapEntry[T, V] {
result := make([]MapEntry[T, V], 0, len(v))
for mk, mv := range v {