group controller

This commit is contained in:
withchao
2023-02-08 14:41:09 +08:00
parent dad31652ad
commit 77edbe1edd
4 changed files with 258 additions and 355 deletions
+10
View File
@@ -144,6 +144,16 @@ func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{} {
})
}
func Filter[E any](es []E, fn func(e E) bool) []E {
rs := make([]E, 0, len(es))
for i := 0; i < len(es); i++ {
if e := es[i]; fn(e) {
rs = append(rs, e)
}
}
return rs
}
// Slice 批量转换切片类型
func Slice[E any, T any](es []E, fn func(e E) T) []T {
v := make([]T, len(es))