12 lines
185 B
Go
12 lines
185 B
Go
|
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
|
||
|
}
|