From c90f789da563fe63f58151a09864932927a8bbac Mon Sep 17 00:00:00 2001 From: hyphen Date: Mon, 26 Feb 2024 16:00:36 +0800 Subject: [PATCH] feat: add to slice --- gmap/gmap.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gmap/gmap.go b/gmap/gmap.go index ee19d59..5c23b01 100644 --- a/gmap/gmap.go +++ b/gmap/gmap.go @@ -37,3 +37,19 @@ func ToSlice[K comparable, V, T any](m map[K]V, fc func(K, V) T) []T { } return ret } + +func CollectKey[K comparable, V any](m map[K]V) []K { + ret := make([]K, len(m)) + for k := range m { + ret = append(ret, k) + } + return ret +} + +func CollectValue[K comparable, V any](m map[K]V) []V { + ret := make([]V, len(m)) + for _, v := range m { + ret = append(ret, v) + } + return ret +}