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.

24 lines
339 B

  1. package gentools
  2. func IndexOf[T comparable](arr []T, value T) int {
  3. for i, v := range arr {
  4. if v == value {
  5. return i
  6. }
  7. }
  8. return -1
  9. }
  10. func AddUniques[T comparable](arr *[]T, values ...T) {
  11. Outer:
  12. for _, v := range values {
  13. for _, v2 := range *arr {
  14. if v2 == v {
  15. continue Outer
  16. }
  17. }
  18. *arr = append(*arr, v)
  19. }
  20. }