Skip to content

Instantly share code, notes, and snippets.

@crhntr
Created December 11, 2022 21:39
Show Gist options
  • Save crhntr/13b93981aa35648920b12638558c6bdf to your computer and use it in GitHub Desktop.
Save crhntr/13b93981aa35648920b12638558c6bdf to your computer and use it in GitHub Desktop.
package main
import "golang.org/x/exp/slices"
func FilterFunc[T any](list []T, keep func(T) bool) []T {
filtered := make([]T, 0, len(list))
for _, e := range list {
if keep(e) {
filtered = append(filtered, e)
}
}
return slices.Clip(filtered)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment