From f6d557d1ba93c7b578733a2d2da6c92f5e3c649c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 21 Jul 2025 08:27:45 -0400 Subject: implement "you control" target constraint --- go/utils/slices.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'go/utils') 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 { -- cgit v1.2.3