group nickname

This commit is contained in:
withchao
2023-02-10 15:36:25 +08:00
parent 5d7809624c
commit 1e1c6de56e
6 changed files with 139 additions and 128 deletions
+5 -4
View File
@@ -144,11 +144,12 @@ 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))
func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T {
rs := make([]T, 0, len(es))
for i := 0; i < len(es); i++ {
if e := es[i]; fn(e) {
rs = append(rs, e)
e := es[i]
if t, ok := fn(e); ok {
rs = append(rs, t)
}
}
return rs