diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-21 08:27:45 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:26 +0200 |
| commit | 80a44e1ee4c02dec693740b21383b71e0a9f5713 (patch) | |
| tree | 4cd7cbe766588c74c2864db352bc04f50f52fd35 /go/utils | |
| parent | e58d14f6e2efe7518bc693ced6e72bdda4c8f35e (diff) | |
| download | muhqs-game-80a44e1ee4c02dec693740b21383b71e0a9f5713.tar.gz muhqs-game-80a44e1ee4c02dec693740b21383b71e0a9f5713.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 { |
