Go doesn't have a built-in filter function. Create one with a loop:
numbers := []int{1, 2, 3, 4, 5, 6}
var evens []int
for _, n := range numbers {
if n%2 == 0 {
evens = append(evens, n)
}
}
// evens is [2, 4, 6]
This pattern appears frequently in Go code. You iterate, check a condition, and collect matches. It's explicit and easy to understand.