26 lines
492 B
Go
26 lines
492 B
Go
package langext
|
|
|
|
func MapKeyArr[T comparable, V any](v map[T]V) []T {
|
|
result := make([]T, 0, len(v))
|
|
for k := range v {
|
|
result = append(result, k)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ArrToMap[T comparable, V any](a []V, keyfunc func(V) T) map[T]V {
|
|
result := make(map[T]V, len(a))
|
|
for _, v := range a {
|
|
result[keyfunc(v)] = v
|
|
}
|
|
return result
|
|
}
|
|
|
|
func CopyMap[K comparable, V any](a map[K]V) map[K]V {
|
|
result := make(map[K]V, len(a))
|
|
for k, v := range a {
|
|
result[k] = v
|
|
}
|
|
return result
|
|
}
|