approveflow/app/utils/collection.go

13 lines
264 B
Go
Raw Permalink Normal View History

2024-11-14 17:02:41 +08:00
package utils
// Filter 泛型过滤函数
func Filter[T any](slice []T, predicate func(T) bool) []T {
var result []T
for _, item := range slice {
if predicate(item) {
result = append(result, item) // 仅添加符合条件的元素
}
}
return result
}