13 lines
155 B
Go
13 lines
155 B
Go
|
package lambda
|
||
|
|
||
|
func Filter[T any](xs []T, fx func(T) bool) []T {
|
||
|
n := 0
|
||
|
for _, x := range xs {
|
||
|
if fx(x) {
|
||
|
xs[n] = x
|
||
|
n++
|
||
|
}
|
||
|
}
|
||
|
return xs[:n]
|
||
|
}
|