gut/generics/misc.go

24 lines
417 B
Go
Raw Normal View History

2024-02-05 23:04:14 +01:00
package generics
// Search for one or more needles in the haystack.
// Returns true if any of the needles was found.
func ContainsAny[T comparable](haystack []T, needle ...T) bool {
for _, n := range needle {
for _, h := range haystack {
if h == n {
return true
}
}
}
return false
}
func IfThen[T any](cond bool, then T, otherwise T) T {
if cond {
return then
} else {
return otherwise
}
}