mirror of
https://github.com/certimate-go/certimate.git
synced 2026-09-24 23:10:13 +08:00
refactor: add maps utility for getting keys
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package maps
|
||||
|
||||
// 获取字典中的所有键组成的切片。
|
||||
//
|
||||
// 入参:
|
||||
// - dict: 字典。
|
||||
//
|
||||
// 出参:
|
||||
// - keys: 字典中的所有键组成的切片。
|
||||
func Keys[Map ~map[K]V, K comparable, V any](dict Map) []K {
|
||||
keys := make([]K, 0, len(dict))
|
||||
for k := range dict {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
Reference in New Issue
Block a user