on haystacks
October 9, 2019 @ 13:10
Go doesn't have a built-in function for finding an object in a list. I found this in some code at work:
// Checks whether an element exists in a slice of integers
func contains(haystack []int, needle int) bool {
for _, n := range haystack {
if needle == n {
return true
}
}
return false
}
I'm quite amused.