aboutsummaryrefslogtreecommitdiff
path: root/go/utils
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-21 08:27:45 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:26 +0200
commit80a44e1ee4c02dec693740b21383b71e0a9f5713 (patch)
tree4cd7cbe766588c74c2864db352bc04f50f52fd35 /go/utils
parente58d14f6e2efe7518bc693ced6e72bdda4c8f35e (diff)
downloadmuhqs-game-80a44e1ee4c02dec693740b21383b71e0a9f5713.tar.gz
muhqs-game-80a44e1ee4c02dec693740b21383b71e0a9f5713.zip
implement "you control" target constraint
Diffstat (limited to 'go/utils')
-rw-r--r--go/utils/slices.go18
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 {