24 lines
417 B
Go
24 lines
417 B
Go
|
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
|
||
|
}
|
||
|
}
|