This commit is contained in:
Andrey Parhomenko 2022-11-25 19:12:25 +05:00
parent df52a9102d
commit 0a23c4a5a4
2 changed files with 6 additions and 6 deletions

View file

@ -30,8 +30,8 @@ func main() {
fmt.Println(m) fmt.Println(m)
fmt.Println(slicex.MakeMap( fmt.Println(slicex.MakeMap(
s, s,
func(v Struct) string { func(s []Struct, i int) string {
return v.Name return s[i].Name
}, },
)) ))

View file

@ -2,14 +2,14 @@ package slicex
func MakeMap[K comparable, V any]( func MakeMap[K comparable, V any](
values []V, values []V,
fn func(V) (K), fn func([]V, int) (K),
) map[K] V { ) map[K] V {
var k K var k K
r := make(map[K] V) r := make(map[K] V)
for _, v := range values { for i, _ := range values {
k = fn(v) k = fn(values, i)
r[k] = v r[k] = values[i]
} }
return r return r