This commit is contained in:
2026-08-22 16:33:18 +02:00
commit a106a26277
14 changed files with 878 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
package utils
import "fmt"
func SliceIndexOf[T any](
s []T,
fn func(T) bool,
) (int, error) {
for i, el := range s {
if fn(el) {
return i, nil
}
}
return -1, fmt.Errorf("failed to find a matching element")
}
func SliceContains[T comparable](s []T, el T) bool {
for _, element := range s {
if element == el {
return true
}
}
return false
}
func SliceContainsCustom[T comparable](s []T, fn func(el T) bool) bool {
for _, el := range s {
if fn(el) {
return true
}
}
return false
}