From cb029abd1afd8d1f0bf38dba6365014741a4167c Mon Sep 17 00:00:00 2001 From: hyphen Date: Mon, 26 Feb 2024 15:56:01 +0800 Subject: [PATCH] feat: add to slice --- gmap/gmap.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gmap/gmap.go b/gmap/gmap.go index 9f75753..ee19d59 100644 --- a/gmap/gmap.go +++ b/gmap/gmap.go @@ -29,3 +29,11 @@ func SafeStore[K comparable, V any, M ~map[K]V](m M, k K, v V) { } m[k] = v } + +func ToSlice[K comparable, V, T any](m map[K]V, fc func(K, V) T) []T { + ret := make([]T, len(m)) + for k, v := range m { + ret = append(ret, fc(k, v)) + } + return ret +}