lambda/filter.go

13 lines
155 B
Go
Raw Normal View History

2022-03-26 19:16:31 +00:00
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]
}