18 lines
344 B
Go
18 lines
344 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
|
|
}
|