gods/slicex/main.go

36 lines
475 B
Go
Raw Normal View History

2022-11-25 16:56:14 +03:00
package slicex
func MakeMap[K comparable, V any](
values []V,
2022-11-25 17:12:25 +03:00
fn func([]V, int) (K),
2022-11-25 16:56:14 +03:00
) map[K] V {
var k K
r := make(map[K] V)
2022-11-25 17:12:25 +03:00
for i, _ := range values {
k = fn(values, i)
r[k] = values[i]
2022-11-25 16:56:14 +03:00
}
return r
}
2022-11-27 22:16:20 +03:00
func ConvStr[V1, V2 ~string](v1 []V1) []V2 {
ret := []V2{}
for i := range v1 {
ret = append(ret, V2(v1[i]))
}
return ret
}
func ConvInt[V1, V2 ~int](v1 []V1) []V2 {
ret := []V2{}
for i := range v1 {
ret = append(ret, V2(v1[i]))
}
return ret
}