summaryrefslogtreecommitdiff
path: root/lib/util/maputil.go
blob: d7f17279c259b272897e94675b420a74cd65a516 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}