12 lines
213 B
Go
12 lines
213 B
Go
![]() |
package utils
|
||
|
|
||
|
func ArrayToMap[T any, V comparable](array []T, key func(T) V) map[V]T {
|
||
|
result := make(map[V]T, len(array))
|
||
|
|
||
|
for _, element := range array {
|
||
|
result[key(element)] = element
|
||
|
}
|
||
|
|
||
|
return result
|
||
|
}
|