summaryrefslogtreecommitdiff
path: root/lib/util/maputil.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-13 20:31:51 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-13 20:31:51 -0600
commit09cc146211148a3b2568261c41a804a802c31d4c (patch)
treee64dc42bb557664333e313e89ddaafa975126e9a /lib/util/maputil.go
parenta0fc940be0ea888c7b380cd95723da65bbd32bcb (diff)
re-organize some things between files
Diffstat (limited to 'lib/util/maputil.go')
-rw-r--r--lib/util/maputil.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/util/maputil.go b/lib/util/maputil.go
new file mode 100644
index 0000000..d7f1727
--- /dev/null
+++ b/lib/util/maputil.go
@@ -0,0 +1,23 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package util
+
+import (
+ "golang.org/x/exp/constraints"
+)
+
+func MapKeys[K comparable, V any](m map[K]V) []K {
+ ret := make([]K, 0, len(m))
+ for k := range m {
+ ret = append(ret, k)
+ }
+ return ret
+}
+
+func SortedMapKeys[K constraints.Ordered, V any](m map[K]V) []K {
+ ret := MapKeys(m)
+ SortSlice(ret)
+ return ret
+}