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

1 year ago
  1. package genutils
  2. func UpsertIntoArray[T comparable](arr []T, values ...T) []T {
  3. outer:
  4. for _, value := range values {
  5. for _, value2 := range arr {
  6. if value2 == value {
  7. continue outer
  8. }
  9. }
  10. arr = append(arr, value)
  11. }
  12. return arr
  13. }
  14. func RemoveFromArray[T comparable](arr []T, values ...T) []T {
  15. for _, value := range values {
  16. for i, value2 := range arr {
  17. if value2 == value {
  18. arr = append(arr[:i], arr[i+1:]...)
  19. break
  20. }
  21. }
  22. }
  23. return arr
  24. }