filter added

This commit is contained in:
Timon Ringwald 2022-09-17 00:04:53 +02:00
parent 84cc7a9e05
commit 55928776b4
1 changed files with 11 additions and 0 deletions

11
filter.go Normal file
View File

@ -0,0 +1,11 @@
package slices
func Filter[T any](slice []T, f func(T) bool) []T {
ret := make([]T, 0, len(slice))
for _, v := range slice {
if f(v) {
ret = append(ret, v)
}
}
return ret
}