This commit is contained in:
withchao
2023-02-03 17:27:56 +08:00
parent a2c4bccdb6
commit bec4a89f7b
3 changed files with 15 additions and 19 deletions
+8
View File
@@ -144,6 +144,14 @@ func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{} {
})
}
func Slice[E any, T any](es []E, fn func(e E) T) []T {
v := make([]T, len(es))
for i := 0; i < len(es); i++ {
v = append(v, fn(es[i]))
}
return v
}
// SliceSet slice to map[E]struct{}
func SliceSet[E comparable](es []E) map[E]struct{} {
return SliceSetAny(es, func(e E) E {