2022-10-27 16:48:26 +02:00
|
|
|
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
|
|
|
|
}
|
2023-01-31 11:01:45 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|