mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-07 14:12:28 +08:00
feat: add package maputil and Keys func
This commit is contained in:
16
maputil/map.go
Normal file
16
maputil/map.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user