golib/helper/text/filter.go

13 lines
257 B
Go
Raw Normal View History

2023-08-20 13:50:39 +08:00
package text
// Filter filters the slice 's' to items which return truth when passed to 'f'.
func Filter(s []string, f func(string) bool) []string {
var out []string
for _, item := range s {
if f(item) {
out = append(out, item)
}
}
return out
}