diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-21 08:27:45 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-22 12:54:28 -0400 |
| commit | f6d557d1ba93c7b578733a2d2da6c92f5e3c649c (patch) | |
| tree | ccc029224388ec2443b46a44170fcc7052982dba /go/utils | |
| parent | 28a858ce697af5f23c3e2ce8b200d4ae4db1a90a (diff) | |
| download | muhqs-game-f6d557d1ba93c7b578733a2d2da6c92f5e3c649c.tar.gz muhqs-game-f6d557d1ba93c7b578733a2d2da6c92f5e3c649c.zip | |
implement "you control" target constraint
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 { |
