package main

import "fmt"

// Filter takes a slice and a predicate function, returning a new slice
// with only the elements that satisfy the predicate
func Filter[T any](slice []T, predicate func(T) bool) []T {
	var result []T
	for _, item := range slice {
		if predicate(item) {
			result = append(result, item)
		}
	}
	return result
}

func main() {
	// Test with integers - filter even numbers
	numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
	evens := Filter(numbers, func(n int) bool {
		return n%2 == 0
	})
	fmt.Println("Even numbers:", evens)

	// Test with strings - filter strings longer than 3 characters
	words := []string{"go", "rust", "python", "c", "javascript", "lua"}
	longWords := Filter(words, func(s string) bool {
		return len(s) > 3
	})
	fmt.Println("Long words:", longWords)

	// Test with floats - filter numbers greater than 5.0
	floats := []float64{1.1, 3.3, 5.5, 7.7, 2.2, 9.9}
	bigFloats := Filter(floats, func(f float64) bool {
		return f > 5.0
	})
	fmt.Println("Big floats:", bigFloats)
}
