From ce04eadb599a5cef223240c546fe3f4961eb8390 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Mon, 13 May 2024 11:31:38 +0200 Subject: [PATCH] add MapKeys method (#32) * add MapKeys method * fix unit test --- algorithms/map.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/algorithms/map.go b/algorithms/map.go index a6a02f5..c40ebf6 100644 --- a/algorithms/map.go +++ b/algorithms/map.go @@ -8,6 +8,14 @@ func MapValues[K comparable, V any](m map[K]V) []V { return s } +func MapKeys[K comparable, V any](m map[K]V) []K { + s := make([]K, 0, len(m)) + for k := range m { + s = append(s, k) + } + return s +} + func Merge(maps ...map[string]interface{}) map[string]interface{} { res := maps[0] for _, m := range maps[1:] {