v0.0.183
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user