filter.go (229B)
1 package slices 2 3 func Filter[T any](items []T, action func(T) bool) (result []T) { 4 result = make([]T, 0, len(items)) 5 for _, item := range items { 6 if !action(item) { 7 continue 8 } 9 result = append(result, item) 10 } 11 return 12 }