From be942ec33e31eb1c3eb8d688184925ab3d3d28c2 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 30 Mar 2022 17:27:50 +0800 Subject: [PATCH] feat: add package maputil and Keys func --- maputil/map.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 maputil/map.go diff --git a/maputil/map.go b/maputil/map.go new file mode 100644 index 0000000..58ce4f2 --- /dev/null +++ b/maputil/map.go @@ -0,0 +1,16 @@ +// Copyright 2021 dudaodong@gmail.com. All rights reserved. +// Use of this source code is governed by MIT license + +// Package maputil includes some functions to manipulate map. +package maputil + +// Keys returns a slice of the map's keys +func Keys[K comparable, V any](m map[K]V) []K { + keys := make([]K, len(m)) + + for k := range m { + keys = append(keys, k) + } + + return keys +}