diff --git a/src/cmd/test/main.go b/src/cmd/test/main.go index 3055a0c..588b1ce 100644 --- a/src/cmd/test/main.go +++ b/src/cmd/test/main.go @@ -30,8 +30,8 @@ func main() { fmt.Println(m) fmt.Println(slicex.MakeMap( s, - func(v Struct) string { - return v.Name + func(s []Struct, i int) string { + return s[i].Name }, )) diff --git a/src/slicex/main.go b/src/slicex/main.go index 0e4f457..369f9b6 100644 --- a/src/slicex/main.go +++ b/src/slicex/main.go @@ -2,14 +2,14 @@ package slicex func MakeMap[K comparable, V any]( values []V, - fn func(V) (K), + fn func([]V, int) (K), ) map[K] V { var k K r := make(map[K] V) - for _, v := range values { - k = fn(v) - r[k] = v + for i, _ := range values { + k = fn(values, i) + r[k] = values[i] } return r