You cannot 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
461 B
Go

package arr
import "joybuywork/internal/consts"
// NotExistAppend 不存在就数组里面就追加
func NotExistAppend[T consts.NormalType](source, adds []T) []T {
if len(source) == 0 {
return adds
}
if len(adds) == 0 {
return source
}
var data = make(map[T]struct{}, len(source))
for _, v := range source {
data[v] = struct{}{}
}
for _, v := range adds {
if _, ok := data[v]; !ok {
source = append(source, v)
}
}
return source
}