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.
 
 
 
 
 
 

42 lines
607 B

package gentools
func IndexOf[T comparable](arr []T, value T) int {
for i, v := range arr {
if v == value {
return i
}
}
return -1
}
func AddUniques[T comparable](arr *[]T, values ...T) {
Outer:
for _, v := range values {
for _, v2 := range *arr {
if v2 == v {
continue Outer
}
}
*arr = append(*arr, v)
}
}
func Map[T any, U any](arr []T, cb func(T) U) []U {
arr2 := make([]U, len(arr))
for i, v := range arr {
arr2[i] = cb(v)
}
return arr2
}
func Flatten[T any](arr [][]T) []T {
arr2 := make([]T, 0, 128)
for _, sub := range arr {
arr2 = sub
}
return arr2
}