To support generic string in stringslice
Closed this issue · 1 comments
BananZG commented
Preflight checklist
- I could not find a solution in the existing issues, docs, nor discussions.
- I agree to follow this project's Code of Conduct.
- I have read and am following this repository's Contribution Guidelines.
- I have joined the Ory Community Slack.
- I am signed up to the Ory Security Patch Newsletter.
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
alnr commented
Use https://pkg.go.dev/slices#Contains instead.