From 2c306efee1cf46bdecd077f3012997aa90c31ef7 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Fri, 13 Sep 2024 19:02:04 +0800 Subject: [PATCH] feat: map to slice --- utils/datautil/datautil.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils/datautil/datautil.go b/utils/datautil/datautil.go index c48dc19..de7c2d1 100644 --- a/utils/datautil/datautil.go +++ b/utils/datautil/datautil.go @@ -284,6 +284,15 @@ func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{} { }) } +// MapToSlice map to slice +func MapToSlice[E any, K comparable](m map[K]E, fn func(e E) K) []E { + es := make([]E, 0, len(m)) + for _, v := range m { + es = append(es, v) + } + return 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++ {