ory/x

To support generic string in stringslice

Closed this issue · 1 comments

Preflight checklist

Ory Network Project

No response

Describe your problem

The current strings and stringslice works fine with string but not custom typed 'enum' string.

Describe your ideal solution

im using code like this locally with ~string type constraint:

// Has returns true if the needle is in the haystack (case-sensitive)
func Has[T ~string](haystack []T, needle T) bool {
	for _, current := range haystack {
		if current == needle {
			return true
		}
	}
	return false
}

Workarounds or alternatives

mapping list of enums into string manually first, then use original stringslice.Has

Version

v0.0.614

Additional Context

open to any comment regarding of using type constraint