diff options
Diffstat (limited to 'go/utils')
| -rw-r--r-- | go/utils/slices.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/go/utils/slices.go b/go/utils/slices.go index eb02f782..d12b4ee0 100644 --- a/go/utils/slices.go +++ b/go/utils/slices.go @@ -1,14 +1,14 @@ package utils -func TypedSliceToInterfaceSlice[T any](s []T) []interface{} { - is := make([]interface{}, 0, len(s)) +func TypedSliceToInterfaceSlice[T any](s []T) []any { + is := make([]any, 0, len(s)) for _, t := range s { is = append(is, t) } return is } -func InterfaceSliceToTypedSlice[T any](s []interface{}) []T { +func InterfaceSliceToTypedSlice[T any](s []any) []T { ts := make([]T, 0, len(s)) for _, t := range s { ts = append(ts, t.(T)) @@ -16,6 +16,18 @@ func InterfaceSliceToTypedSlice[T any](s []interface{}) []T { return ts } +func InterfaceSliceContains[T comparable](s []any, o T) bool { + for _, _t := range s { + switch t := _t.(type) { + case T: + if t == o { + return true + } + } + } + return false +} + func RemoveFromUnorderedSlice[T comparable](s []T, o T) []T { for i, t := range s { if t != o { |
